#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int min_cost(int n, vector<int> &heights, vector<int> &costs) {
    vector<int> dp(n, 0);
    dp[0] = costs[0];

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

        for (int j = 0; j < i; j++) {
            if (heights[j] > heights[i]) {
                dp[i] = min(dp[i], dp[j] + costs[i]);
            }
        }
    }

    return dp[n - 1];
}

int main() {
    int n;
    cin >> n;

    vector<int> heights(n), costs(n);

    for (int i = 0; i < n; i++) {
        cin >> heights[i];
    }

    for (int i = 0; i < n; i++) {
        cin >> costs[i];
    }

    cout << min_cost(n, heights, costs) << endl;

    return 0;
}
