#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main (){
       ios_base::sync_with_stdio(0);
       ll t , q , f , l , r , x , y , i , n , m , j , k , mn = 2e9, mx = -2e9;
       cin>>n;
       ll sum=0;
        ll a[n+18];
        map<ll,ll>mp;
       for(i=0;i<n;i++){
          cin>>a[i];
          mp[a[i]]++;
          if(mp[a[i]]==1){
               sum+=a[i];
          }
       }
        ll b[n+18];
        map<ll,ll>us;
        ll cum=0;
       for(i=0;i<n;i++){
          cin>>b[i];
          us[b[i]]++;
          if(us[b[i]]==1){
               cum+=b[i];
          }
       }
       cout<<min(cum,sum);
 }