#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long
int a[20];
int a_ = -1, b_ = -1;
signed main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n; i++) {
		int k; cin >> k;
		if (a[i]) {
			if (a_ < 0)a_ = k;
			else a_ = min(a_, k);
		}
		else{
			if (b_ < 0)b_ = k;
			else b_ = min(b_, k);
		}
	}
	if (a_ < 0 || b_ < 0)cout << "0\n";
	else cout << a_ + b_ << endl;
}
