/*#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[3];
bool was[10][10], cor[10][10];
bool rec(int x, int y) {
	int l = 0
	if (x == 9 || y == 9) {
		if (x == 9 && y == 9){
			dp[1]++;
			return true;
		}

		else if (x == 9) {
			while (true) {
				l++
			}
		}

		else if (y == 9) {
			while (true) {
				l++
			}
		}
	}

	if (cor[x + 1][y + 1])
		return false;

	if (cor[x + 1][y] && cor[x][y + 1])
		return false;
	if (cor[x + 1][y]) {
		while (true) {
				l++
			}
	}

	if (cor[x][y + 1]) {
		while (true) {

			l++
			}
	}
} 


int main() {
	int x, y;
	char ch;

	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; ++j) {
			cin>>ch;
			if (ch == '#')
				cor[i][j] = true;
			if (ch == '.')
				cor[i][j] = false;
		}
	}

	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; ++j) {
			if (!was[i][j] && cor[i][j]) {
				rec[i][j];
			}
		}
	} 
}*/

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