/*
#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);
	//setlocal(LC_ALL, "EN");
	map<char, int> mp {
		{'0', 0},
		{'1', 1},
		{'2', 5},
		{'3', 3},
		{'4', 4},
		{'5', 2},
		{'6', 6},
		{'7', 7},
		{'8', 8},
		{'9', 9}
	};
	string st;
	int l = 0;
	cin>>st;

	for (int i = st.size() - 1; i >= 0; i--) {
	    l *= 10;
		l += mp[st[i]];
	}

	cout<<l;
}



*/

#include <iostream>
#include<string>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int 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]=1e9;}
        h[n+1]=0;
        dp[0]=0;
        dp[1]=0;
     
    for(int i=1; i<=n; i++){
        cin>>c[i];}
    for(int i=1; i<=n; i++){
        int g;
        g=i;
        while(h[i]>=h[g]){
         
            dp[g+1]=min(dp[g+1],dp[i]+c[i]);
              g++;
        }
          g=i;
        while(h[i]>=h[g]){
            
            dp[i+1]=min(dp[i+1],dp[g]+c[i]);
             g--;
        }
    }
        
        
  cout<<dp[n+1];
            
}