#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main(){
    int n;
    cin >> n;
    vector<int> heights(n), price(n);

    for(int& h : heights){
        cin >> h;
    }

    for(int& p : price){
        cin >> p;
    }

    vector<int> dp(n, LLONG_MAX);

    dp[0] = price[0];

    for(int i = 1; i < n; i++){
        dp[i] = dp[i-1] + price[i];

        int maxh = heights[i];

        for (int j = i - 1; j >= 0; j--){
            if(heights[j] > maxh){
                break;
            }
            maxh = max(maxh, heights[j]);
            if(j == 0){
                dp[i] = min(dp[i], price[i]);
            }
            else{
                dp[i] = min(dp[i], dp[j - 1] + price[i]);
            }
        }
    }

    cout << dp[n - 1] << endl; 
    return 0;
}