#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define vl vector<ll>
#define pstr pair<string, string>
#define lli long long int
#define ll long long
#define ld long double
#define ull unsigned long long
#define sz size()
#define pb push_back
#define pob pop_back
#define pf push_front
#define ff first
#define ss second
#define F first
#define S second
#define mk make_pair
#define fr front()
#define PI 3.14159265358979323846
using namespace std;
const ll MOD = 1e9 + 7;
const ll N = 2e5 + 5;
const ll inf = 1e18;
const ll maxsize = 105;

ll binpow(ll a, ll b){
    if(b == 1) return a;
    ll z = binpow(a, b / 2);
    if(b % 2 == 0) return (z * z);
    else return (z * z) * a ;
}

ll binpow_m(ll a, ll b){
    if(b == 1) return a % MOD;
    ll z = binpow(a, b / 2);
    if(b % 2 == 0) return (z * z) % MOD;
    else return (z * z) % MOD * a % MOD;
}

ll lcm(ll a, ll b) {
    return (a / __gcd(a, b)) * b;
}

ll Prime(unsigned long a, unsigned long j){
   return j * j <= a ? (a % j) && Prime(a, j + 1) : 1;
}

bool isPrime(ll n){
    for(ll i = 2; i <= sqrt(n); i++){
        if(n % i == 0){
            return false;
        }
    }
    return true;
}
ll n,a[N],b[N],p[N];
pll t[N*4];
void build(ll v,ll l,ll r){
    if(l==r){
        t[v]={a[l],l};
        return;
    }
    ll m=(l+r)/2;
    build(v*2,l,m);
    build(v*2+1,m+1,r);
    t[v]=max(t[v*2],t[v*2+1]);
}
pll get(ll v,ll l,ll r,ll ql,ll qr){
    if(ql<=l&&r<=qr)return t[v];
    if(r<ql||qr<l)return {0,0};
    ll m=(l+r)/2;
    pll m1=get(v*2,l,m,ql,qr);
    pll m2=get(v*2+1,m+1,r,ql,qr);
    return max(m1,m2);
}
ll f(ll l,ll r){
    if(l>r)return 0;
    auto [m,p]=get(1,1,n,l,r);
    ll m1=f(l,p-1), m2=f(p+1,r);
    return b[p]+min(m1,m2);
}
int main(/*d!ZzAsTer?*/)
{
    boost;
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    cin>>n;
    for(ll i=1;i<=n;i++) cin>>a[i];
    for(ll i=1;i<=n;i++) cin>>b[i], p[i]=p[i-1]+b[i];
    build(1,1,n);
    cout<<f(1,n);
    return 0;
}
