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


int main() {
    int n;
    cin >> n;
    int arr[n];
    int arr2[n];
    
    for(int i =0; i < n; i++)
    {
        cin >> arr[i];
    }
    for(int i =0; i < n; i++)
    {
        cin >> arr2[i];
    }
    if(n == 1)
    {
        cout << arr2[0];
        return 0;
    }
    auto num1 = max_element(arr, arr+n);
    int max_index = num1 - arr;
    auto num2 = min_element(arr, arr+n);
    int min_index = num2 - arr;
    cout << arr2[max_index] + arr2[min_index];
}
