#include <bits/stdc++.h>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> left, right;
    vector<int> lr(N);
    for (int i = 0; i < N; i++) cin >> lr[i];
    for (int t : lr) {
        int a;
        cin >> a;
        if (t == 0)
            right.push_back(a);
        else
            left.push_back(a);
    }
    if (min(right.size(), left.size()) == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    sort(right.begin(), right.end());
    sort(left.begin(), left.end());
    cout << right[0] + left[0] << endl;
    return 0;
}
