#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <string>
#include <set>
#include <iomanip>
#include <stack>
#include <cctype>

using namespace std;
#define ll long long
#define ld long double
#define print(a) for (auto i: a){cout << i << " ";}cout << endl;
#define dprint(a) for (ll i = 0; i < a.size(); i++){ cout << i << ": ";for(auto j: a[i]){cout << j << "\t";}cout << endl;}cout << endl;
#define open(name_input, name_output) freopen(name_input, "r", stdin); freopen(name_output, "w", stdout);
#define input(a, n) for(ll i = 0; i < n; i++){cin>>a[i];}
#define tests ll number_of_tests; cin>>number_of_tests; while(number_of_tests--)
#define slprint(sl) for(auto i: sl){ cout << i.first << " " << i.second << endl;}


vector<ll> c(200000);
vector<ll> h(200000);

ll f(ll l, ll r) {
    ll ind = l;
    for (int i = l; i < r; ++i) {
        if (h[i] > h[ind]) {
            ind = i;
        }
    }
    if (ind == l || ind == r - 1) {
        return c[ind];
    }
    return c[ind] + min(f(l, ind), f(ind + 1, r));
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    input(h, n);
    input(c, n);
    cout << f(0, n);

}




