#include <iostream>
using namespace std;

int main()
{
	int n, rm = 1001, lm = 1001;
	int a[10], w;

	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++) {
		cin >> w;

		if (a[i] == 0 && rm > w)
			rm = w;
		else if (a[i] == 1 && lm > w)
			lm = w;
	}

	if (rm == 1001 || lm == 1001)
		cout << 0 << endl;
	else
		cout << rm + lm << endl;
	
	return 0;
}
