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

int minRoofCost(vector<int>& heights, vector<int>& costs, int left, int right) {
    if (left == right) {
        return costs[left];
    }

    int max_height = -1;
    int max_index = -1;

    // Найдем самую высокую колонну в заданном диапазоне
    for (int i = left; i <= right; i++) {
        if (heights[i] > max_height) {
            max_height = heights[i];
            max_index = i;
        }
    }

    int min_cost_left = minRoofCost(heights, costs, left, max_index - 1);
    int min_cost_right = minRoofCost(heights, costs, max_index + 1, right);

    int current_cost = costs[max_index];

    int total_cost = min(min_cost_left, min_cost_right) + current_cost;

    return total_cost;
}

int main() {
    int n;
    cin >> n;
    vector<int> heights(n);
    vector<int> costs(n);

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

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

    int result = minRoofCost(heights, costs, 0, n - 1);
    cout << result << endl;

    return 0;
}
