#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(){
  ll n,vl=1e9,vr=1e9,a[11];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++){
      ll w; cin>>w;
      if(a[i]==0)vl=min(vl,w);
      if(a[i]==1)vr=min(vr,w);
  }
  if(vl==1e9||vr==1e9)cout<<0<<endl;
  else cout<<vl+vr<<endl;
  return 0;
}

