#include <iostream>
#include <vector>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("avx2")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune="auto"")

//mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());

#define N (int)2e5

typedef pair<int, int> T;
int INF = 1e9;

T tree[N*4];
int arr[N];
int n;
int base;

void build() {
    if (__builtin_popcount(n) == 1) base = n;
    else {
        int i = 0;
        base = n;
        while (__builtin_popcount(base) != 1) {
            base >>= 1;
            i++;
        }
        i++;
        base <<= i;
    }
    for (int i = 0; i < base; i++) tree[i+base] = {arr[i], i};
    for (int i = base-1; i >= 1; i--) tree[i] = max(tree[i<<1], tree[i<<1|1]);
}

T get(int ql, int qr, int i = 1, int l = 0, int r = base) {
    if (ql >= r || qr <= l) return {-INF, 0};
    if (ql <= l && qr >= r) return tree[i];
    int m = (l + r) / 2;
    return max(
                get(ql, qr, i<<1  , l, m),
                get(ql, qr, i<<1|1, m, r)
    );
}
int prices[N];

int getPrice(int l = 0, int r = n) {
    int now = get(l, r).second;
    //cout << "debug: " << now << endl;
    if (now == l || now == r-1) return prices[now];
    return prices[now] + min(getPrice(l, now), getPrice(now+1, r));
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    for (int i = 0; i < N; i++) {
        arr[i] = -INF;
    }
    cin >> n;
    for (int i = 0; i < n; i++) cin >> arr[i];
    for (int i = 0; i < n; i++) cin >> prices[i];
    build();
    /*
    for (int i = 0; i < base; i++) cout << arr[i] << ' ';
    int l, r;
    while (1) {
        cin >> l >> r;
        cout << get(l, r).first << endl;
    }
    //*/
    cout << getPrice();

    return 0;
}
