#include <bits/stdc++.h>
#define fi first
#define se second

using namespace std;
typedef long long ll;

ll f(vector<ll> &h, vector<ll> &c, ll mi, ll k){
    if(k == 1){
        return c[mi];
    } else {
        vector<ll> hl, cl, hr, cr;
        for(int i = 0; i < mi; i++){
            hl.push_back(h[i]);
        }
        for(int i = 0; i < mi; i++){
            cl.push_back(c[i]);
        }
        ll ml = 0, kl, m = h[0];
        for(int i = 1; i < mi; i++){
            if(h[i] > m){
                m = h[i];
                ml = i;
            }
        }
        if(ml == 0 or ml == mi - 1){
            kl = 1;
        }else{
            kl = 2;
        }
        for(int i = mi + 1; i < h.size(); i++){
            hr.push_back(h[i]);
        }
        for(int i = mi + 1; i < h.size(); i++){
            cr.push_back(c[i]);
        }
        ll mr = mi + 1, kr;
        m = h[mi + 1];
        for(int i = mi + 2; i < h.size(); i++){
            if(h[i] > m){
                m = h[i];
                mr = i;
            }
        }
        mr -= (mi + 1);
        if(mr == 0 or mr == mi - 1){
            kr = 1;
        }else{
            kr = 2;
        }
        return min(f(hl, cl, ml, kl), f(hr, cr, mr, kr)) + c[mi];
    }
}

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

    int n, k;
    cin >> n;
    vector<ll> h(n), c(h);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    ll m = h[0], mi = 0;
    for(int i = 1; i < n; i++){
       if(h[i] > m){
           m = h[i];
           mi = i;
       }
    }
    if(mi == 0 or mi == n - 1){
        k = 1;
    }else{
        k = 2;
    }
    cout << f(h, c, mi, k);
}
