#include<bits\stdc++.h>
#define ll long long
#define ls u << 1
#define rs u << 1 | 1
#define sz(x) (int) x.size()
#define pb push_back
using namespace std;
const int N = 2e5 + 15;
int n, h[N], c[N];
pair<int, int> tr[N << 2];
void build(int u, int l, int r) {
	if(l == r) {
		tr[u] = {h[l], l};
		return;
	}
	int m = (l + r) / 2;
	build(ls, l, m);
	build(rs, m + 1, r);
	tr[u] = max(tr[ls], tr[rs]);
}
pair<int, int> get(int ql, int qr, int u = 1, int l = 1, int r = n) {
	if(ql > r or l > qr) {
		return {0, 0};
	}
	if(ql <= l && r <= qr) {
		return tr[u];
	}
	int m = (l + r) / 2;
	return max(get(ql, qr, ls, l, m), get(ql, qr, rs, m + 1, r));
}
ll solve(int l,int r) {
	if(l > r) {
		return 0;
	}
	if(l == r) {
		return c[l];
	}
	int pos = get(l, r).second;
	int res = min(c[pos] + solve(pos + 1, r), c[pos] + solve(l, pos - 1));
	return res;
}
int main() { 
  	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	cin >> n;
  	for(int i = 1; i <= n; i++) {
  		cin >> h[i];
	}
	for(int i = 1; i <= n; i++) {
  		cin >> c[i];
	}
	build(1, 1, n);
	cout << solve(1, n);
}
