#include <bits/stdc++.h>
using namespace std;

struct SegmentnoeDerevo {
    vector<pair<long long, long long>> derevo;
    long long razmer;

    void initsializirovat(long long n) {
        razmer = 1;
        while (razmer < n) razmer *= 2;
        derevo.assign(razmer * 2 - 1, make_pair(LLONG_MIN, -1));
    }

    void postroit(vector<long long> &a, long long x, long long lx, long long rx) {
        if (rx - lx == 1) {
            derevo[x].second = lx;
            if (lx < a.size()) {
                derevo[x].first = a[lx];
            }
        } else {
            long long m = (lx + rx) / 2;
            postroit(a, x * 2 + 1, lx, m);
            postroit(a, x * 2 + 2, m, rx);
            derevo[x] = obiedinit(derevo[x * 2 + 1], derevo[x * 2 + 2]);
        }
    }

    void postroit(vector<long long> &a) {
        initsializirovat(a.size());
        postroit(a, 0, 0, razmer);
    }

    pair<long long, long long> obiedinit(pair<long long, long long> a, pair<long long, long long> b) {
        if (a.first > b.first) {
            return a;
        } else {
            return b;
        }
    }

    pair<long long, long long> minimum(long long l, long long r, long long x, long long lx, long long rx) {
        if (lx >= r or l >= rx) {
            return make_pair(LLONG_MIN, -1);
        }
        if (lx >= l and rx <= r) {
            return derevo[x];
        }
        long long m = (lx + rx) / 2;
        auto s1 = minimum(l, r, x * 2 + 1, lx, m);
        auto s2 = minimum(l, r, x * 2 + 2, m, rx);
        return obiedinit(s1, s2);
    }

    long long minimum(long long l, long long r) {
        return minimum(l, r, 0, 0, razmer).second;
    }
};

long long glavnaya;
vector<long long> stoimosti;
vector<long long> znacheniya;
SegmentnoeDerevo segmentnoeDerevo;

long long reshenie(long long l, long long r) {
    if (r - l == 1) {
        return stoimosti[l];
    } else if (r - l == 0) {
        return 0;
    }
    long long poz = segmentnoeDerevo.minimum(l, r);
    long long levoeZnachenie = reshenie(l, poz);
    long long pravoeZnachenie = reshenie(poz + 1, r);
    return min(levoeZnachenie, pravoeZnachenie) + stoimosti[poz];
}

void reshitProblemu() {
    cin >> glavnaya;
    segmentnoeDerevo = SegmentnoeDerevo();
    stoimosti.assign(glavnaya, 0);
    znacheniya.assign(glavnaya, 0);

    for (long long i = 0; i < glavnaya; i++) {
        cin >> znacheniya[i];
    }
    for (long long i = 0; i < glavnaya; i++) {
        cin >> stoimosti[i];
    }

    segmentnoeDerevo.postroit(znacheniya);
    cout << reshenie(0, glavnaya);
}

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

    long long testovyeKejsy = 1;
    for (long long i = 1; i <= testovyeKejsy; i++) {
        reshitProblemu();
        cout << endl;
    }

    return 0;
}
