#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
int main(){
  ll n;cin>>n;
  ll sa=0,sb=0;
  ll a[n],b[n];
  vector<ll> v;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
    sa+=a[i];
    sb+=b[i];
    v.push_back(a[i]);
    v.push_back(b[i]);
  }
  sort(v.begin(),v.end());
  ll ss=0;
  for(int i=0;i<n;i++)ss+=v[i];
  ll ans=min(sa,sb);
  for(int i=0;i<n;i++){
    ll sum=a[i]+b[i];
    if(a[i]>b[i])swap(a[i],b[i]);
    ll h=v[n-1];
    ll k=ss;
    if(h>=b[i]){
      k-=a[i]+b[i];
    }
    else if(h>=a[i]){
      if(a[i]>=v[n-3])k-=v[n-1]+v[n-2];
      else k-=v[n-1]+a[i];
    }
    else{
      k-=v[n-1]+v[n-2];
    }
    ans=min(ans,sum+k);
  }
  cout<<ans<<endl;
}
