#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;


int main() {
	int N;cin>>N;
	vector<int>ls(N),nums(N);
	for(int i=0;i<N;++i)cin>>ls[i];
	for(int i=0;i<N;++i)cin>>nums[i];

	int min_l=1e9+1,min_r=1e9+1;
	for (int i = 0; i < N; ++i) {
		if (ls[i]) {
			min_r=min(min_r,nums[i]);
		}
		else {
			min_l=min(min_l,nums[i]);
		}
	}
	if(min_l+min_r>=1e9)cout<<0<<endl;
	else {
		cout<<min_l+min_r<<endl;
	}
	return 0;
}
