#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n; cin >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	rep(i, n) {
		cin >> b[i];
	}
	int x = 10000; int y = 10000;
	for (int i = 0; i < n; i++) {
		if (a[i] == 0) x = min(x, b[i]);
		else y = min(y, b[i]);
	}
	if (x == 10000 || y == 10000) cout << 0 << endl;
	else cout << x + y << endl;
	return 0;
}
