#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<long long> h(n), c(n), maxx(n), dp(n), pos(n);
    long long mx = 0;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
        if (mx < h[i]) {
            maxx[i] = h[i];
            pos[i] = i;
            mx = h[i];
        }
        else {
            maxx[i] = maxx[i - 1];
            pos[i] = pos[i - 1];
        }

    }
    for (long long& x : c) {
        cin >> x;
    }

    dp[0] = c[0];
    if (maxx.back() == h[0]) {
        cout << c[0];
        return 0;
    }
    else if (maxx.back() == h[n - 1]) {
        cout << c.back();
        return 0;
    }

    for (int i = 1; i < n; ++i) {
        if (maxx[i] == h[0]) {
            dp[i] = c[0];
            assert(pos[i] == 0);
        }
        else if (maxx[i] == h[i]) {
            dp[i] = c[i];
            assert(pos[i] == i);
        }
        else {
            dp[i] = min(dp[i - 1] + c[i], dp[pos[i] - 1] + c[pos[i]]);
            if (i - 2 >= 0) {
                int cc;
                if (h[i - 1] > h[i]) {
                    cc = c[i - 1];
                }
                else {
                    cc = c[i];
                }
                dp[i] = min(dp[i], dp[i - 2] + cc);
            }
        }
    }

    cout << dp.back();

    if (maxx[n - 1] == h[0]) {
        assert(dp.back() == c[0]);
    }
    else if (maxx[n - 1] == h[n - 1]) {
        assert(dp.back() == c[n - 1]);
    }

    return 0;
}