#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N;
vector<int> A,B;
int which[10],value[10];


int main(){

	int num_0 = 0,num_1 = 0;

	scanf("%d",&N);

	for(int i = 0; i < N; i++){

		scanf("%d",&which[i]);

		if(which[i] == 0){

			num_0++;
		}else{

			num_1++;
		}
	}

	if(num_0 == 0 || num_1 == 0){

		printf("0\n");
		return 0;
	}

	for(int i = 0; i < N; i++){

		scanf("%d",&value[i]);

		if(which[i] == 0){

			A.push_back(value[i]);

		}else{

			B.push_back(value[i]);
		}
	}

	sort(A.begin(),A.end());
	sort(B.begin(),B.end());

	printf("%d\n",A[0]+B[0]);

	return 0;
}

