#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main(){
    vector<pair<ll,ll>> p;
    ll N;
    cin >> N;
    for(ll i=0;i<N;i++){
        ll A,B;
        cin >> A >> B;
        p.push_back(make_pair(A,i*2+0));
        p.push_back(make_pair(B,i*2+1));
    }
    sort(p.begin(),p.end());

    bool allsame=true;
    bool checked[100000];
    ll sum=0;
    for(int i=0;i<N;i++) checked[i]=false;
    for(ll i=0;i<N;i++){
        allsame=(allsame && (p[0].second%2)==(p[i].second%2));
        checked[p[i].second/2]=true;
        sum+=p[i].first;
    }
    for(int i=0;i<N;i++){
        if(checked[i]==false){
            cout << sum << endl;
            return 0;
        }
    }
    if(allsame){
        cout << sum << endl;
        return 0;
    }
    if(p[N-1].second/2!=p[N].second/2){
        cout << sum-p[N-1].first+p[N].first << endl;
    }else{
        cout << min(sum-p[N-1].first+p[N+1].first,sum-p[N-2].first+p[N].first) << endl;
    }

    
    return 0;
}