#include<bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n + 1], c[n + 1];
    vector <pair <int, int> > v;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    for (int i = 0; i < n; i++) {
        v.push_back(make_pair(a[i], c[i]));
    }
    sort (v.begin(), v.end());
    if (v.size() - 1 == 0) {
        cout << v[0].second;
        return 0;
    }
    cout << v[0].second + v[v.size() - 1].second;
}
