/*#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 dp[1000005][1000005];
dp[1][1] = 1;
dp[2][2] = 12;
dp[2][1] = 4;
dp[1][2] = 4;
void rec(int m, int n) {

}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m;
	cin>>n>>m;

	dp[n + 3][m + 3];
	dp[1][1] = 1;
	dp[2][2] = 12;
	dp[2][1] = 4;
	dp[1][2] = 4;

	rec(min(n, m) - 1, max(n, m));
}

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