#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long

using namespace std;

void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
int pow(int a,int b,int m){int ans=1;while(b){if(b&1){ans=(ans*a)%m;}b>>=1;a=(a*a)%m;}return ans;}
int binpow(int a,int b){int ans=1;while(b){if(b&1){ans=(ans*a);}b>>=1;a=(a*a);}return ans;}

const int N = 2e5 + 100, mod = 1e9 + 7, inf = 1e9;

 
int a[N], b[N];
int n;

int calc(int l ,int r){
	if(l > r)return 0;
	if(l == r) return b[l];
	int mid = (l + r) >> 1;
	int ind = l, mn = -inf;
	for(int i = l; i <= r; i++){
		if(a[i] > mn){
			mn = a[i];
			ind = i;
		}
	}
	//cout << ind << endl;
	int res =  b[ind]+ min(calc(l, ind - 1), calc(ind + 1, r));
	return res;
}
main(){
	iostream::sync_with_stdio(false);	
    cin.tie(nullptr);
    cout.tie(nullptr);
   // memset(dp, -1, sizeof(dp));
    cin >> n;
    for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	 for(int i = 1; i <= n; i++){
		cin >> b[i];
	}
	cout << calc(1, n)<< endl;

}

