#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

/*
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
*/

int N;
bool rl[100];
bool check[2] = {};
int b = INF, x = INF;
int a, w;

int main() {
	cin >> N;
	REP(i, N) {
		cin >> rl[i];
		check[rl[i]] = true;
	}
	REP(i, N) {
		if (rl[i] == 0)
		{
			cin >> a;
			b = min(b, a);
		}
		else {
			cin >> w;
			x = min(x, w);
		}
	}
	if (!check[0] || !check[1]) {
		cout << 0 << endl;
		return 0;
	}
	
	cout << b + x << endl;
}
