/*#include <bits/stdc++.h>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <string> 
 
#define pb push_back
#define ll long long
#define f first
#define s second

const ll int INF = 1e18, inf = 1e9, mod = 1e9 + 7;


using namespace std;


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m, k;
	cin>>n>>m;
	k = log2()
	pair<int, int> pr[10000];
	for (int i = 0; i < n; i++) {
		cin>>m;

	}
}
*/

#include <iostream>
#include<vector>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> h, c, dp;
    for(int i=1; i<=n; i++){
        int temp;
        cin>>temp;
        h.push_back(temp);}
        for(int i=1; i<=2*n; i++){
        dp.push_back(1e19);}
        h[n+1]=0;
        dp[0]=0;
     h[0]=0;
    for(int i=0; i<n; i++){
        int temp;
        cin>>temp;
        c.push_back(temp);}
    for(int i=0; i<n; i++){
        int g, s;
        g=i;
        s=i;
         while(h[i]>=h[g]){
            dp[g+1]=min(dp[g+1],dp[i]+c[i]);
              g++;
        }
          while(h[i]>=h[s]){
            dp[i+1]=min(dp[i+1],dp[s]+c[i]);
             s--;
        }
        g=i;
        while(h[i]>=h[g]){
            dp[g+1]=min(dp[g+1],dp[i]+c[i]);
              g++;
        }
        //cout<<dp[i]<<" ";
    }
        
        
  cout<<dp[n+1];
            
}