#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;}

int n;
vector<ll> c(200000);
vector<ll> a(200000);

vector <pair<ll, ll>> t;

void build(ll v, ll l, ll r) {
    if (r - l == 1) {
        t[v].first = a[l];
        t[v].second = l;
    }
    else {
        ll m = (l + r) / 2;
        build(2 * v + 1, l, m);
        build(2 * v + 2, m, r);
        t[v] = t[2 * v + 1];
        if (t[v] < t[2 * v + 2]){
            t[v] = t[2 * v + 2];
        }
    }
}


pair<ll, ll> get_max(ll v, ll l, ll r, ll a, ll b) {
    if (b <= l || r <= a) {
        return make_pair(-10e10, -1);
    }
    if (a <= l && r <= b) {
        return t[v];
    }
    ll m = (r + l) / 2;
    if (get_max(2 * v + 1, l, m, a, b).first >  get_max(2 * v + 2, m, r, a, b).first){
        return get_max(2 * v + 1, l, m, a, b);
    }
    return get_max(2 * v + 2, m, r, a, b);
}

ll f(ll l, ll r) {
    ll ind = get_max(0, 0, n, l, r).second;
    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);
    cin >> n;
    input(a, n);
    input(c, n);
    t.assign(4 * n, make_pair(-10e10, -1));
    build(0, 0, n);
    cout << f(0, n);

}




