#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int N= 2e5 + 9;
const ll inf = 1e18;

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

ll dnc(int l, int r){
	if(l > r) return inf;
	if(l == r) return b[l];
	int id = l;
	for(int i = l; i <= r; i++)
		if(a[i] > a[id]) id = i;
	return b[id] + min(dnc(l, id - 1), dnc(id + 1, r));	
}

void solve(){
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) cin >> b[i];
	cout << dnc(1, n);
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
	return 0;
}