#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const ll inf = 1e18;

signed main() {
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll> c(n + 1, inf), h(n + 1, inf);
    for (ll i = 1; i <= n; i++)
        cin >> h[i];
    for (ll i = 1; i <= n; i++)
        cin >> c[i];

    vector<ll> dp(n + 1, 0);
    deque<ll> a;
    a.push_back(0);
    for (ll i = 1; i <= n; i++) {
        while (h[a.back()] < h[i]) {
            a.pop_back();
        }
        ll j = a.back();
        if (h[j] > h[i]) {
            dp[i] = min(dp[j - 1] + c[j],
                        dp[j] + c[i]);
        }
        else {
            dp[i] = min(dp[j - 1] + c[j] + c[i],
                        dp[j] + c[i]);
        }
        a.push_back(i);
    }
    cout << dp[n];
}