#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vct;
ll h[200000];
ll c[200000];
ll rec(ll l, ll r, ll sm) {
	ll mx = l;
	if (l >= r - 1) {
		return sm + c[l];
	}
	for (int i = l; i < r; ++i) {
		if (h[mx] < h[i]) {
			mx = i;
		}
	}
	if (mx == r - 1 || mx == l) {
		sm += c[mx];
		return sm;
	} 
	return min(rec(l, mx, sm + c[mx]), rec(mx + 1, r, sm + c[mx]));
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	} 
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	} 
	cout << rec(0, n, 0);
}
