#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<queue>
#include<utility>
#define LL long long
using namespace std;



int main() {
	int N, a[20], w[20], rmin=10000, lmin=10000;
	cin >> N;
	for (int i = 0; i < N; i++)cin >> a[i];
	for (int i = 0; i < N; i++) {
		cin >> w[i];
		if (a[i])rmin = min(rmin, w[i]);
		else lmin = min(lmin, w[i]);
	}
	if (rmin == 10000 || lmin == 10000)cout << 0 << endl;
	else cout << rmin + lmin << endl;

	return 0;
}



