#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a[10],b[10],cl=0,cr=0,minl=1000,minr=1000;
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>a[i];
    if(a[i]) ++cl;
    else ++cr;
  }
  for(int i=0;i<n;++i) cin>>b[i];
  if(cl==0||cr==0) cout<<"0"<<endl;
  else{
    for(int i=0;i<n;++i){
      if(a[i]) minr=min(minr,b[i]);
      else minl=min(minl,b[i]);
    }
    cout<<minl+minr<<endl;
  }
  return 0;
}

