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

bool cmp(pair <int, int> x, pair <int, int> y){
    return x.first > y.first;
}

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