#include <vector>
#include <iostream>
#define int long long
using namespace std;
signed main() {
    int n;
    cin >> n;
    vector<int> h(n,0), c(n,0);
    vector<int> d(n+1, -1);
    for(int i=0;i<n;i++)cin >> h[i];
    for(int i=0;i<n;i++)cin >> c[i];
    d[0] = 0;
    for(int i=0;i<n;i++){
        if(d[i]== -1)continue;
        int lm = h[i];
        d[i+1] = d[i+1]==-1?d[i]+c[i]:min(d[i+1],d[i]+c[i]);
        bool p = false;
        for(int j=i+1;j<n;j++){
            if(h[j]>lm){
                p = true;
                d[j+1] = d[j+1]==-1?d[i]+c[j]:min(d[j+1], d[i]+c[j]);
                lm = h[j];
            }else if(h[j]<h[i] and !p){
                d[j+1] = d[j+1]==-1?d[i]+c[i]:min(d[j+1], d[i]+c[i]);
            }
        }
    }
    cout << d[n];
    return 0;
}
