#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n),b(n);
  for(Int i=0;i<n;i++) cin>>a[i]>>b[i];
  using P = pair<Int, Int>;
  vector<P> v;
  for(Int i=0;i<n;i++) v.emplace_back(a[i],i);
  for(Int i=0;i<n;i++) v.emplace_back(b[i],n+i);
  sort(v.begin(),v.end());

  Int sum=0;
  vector<Int> used(n*2,0);
  for(Int i=0;i<n;i++){
    sum+=v[i].first;
    used[v[i].second]=1;
  }
  
  for(Int k=0;k<=n;k+=n){
    Int flg=1;
    for(Int i=0;i<n;i++) flg&=used[k+i];
    if(flg){
      cout<<sum<<endl;
      return 0;
    }
  }

  for(Int i=0;i<n;i++){
    if(used[i]&&used[n+i]){
      cout<<sum<<endl;
      return 0;
    }
  }
  
  Int ans=sum+v[n].first;
  for(Int i=0;i<n;i++){
    Int res=sum-v[i].first;
    res+=v[n+((v[i].second%n)==(v[n].second%n))].first;
    chmin(ans,res);
  }
  cout<<ans<<endl;
  return 0;
}
