#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=200005;
int n,vis[N];
pii a[N*2];
ll ans1,ans2,ans3;
int main(){
	scanf("%d",&n);
	For(i,1,n){
		int x,y;
		scanf("%d%d",&x,&y);
		a[i]=pii(x,i);
		a[i+n]=pii(y,-i);
		ans1+=x; ans2+=y;
	}
	sort(a+1,a+2*n+1);
	bool ok=0;
	For(i,1,n){
		ans3+=a[i].fi;
		if (vis[abs(a[i].se)]) ok=1;
		vis[abs(a[i].se)]=1;
	}
	if (!ok){
		int dif=1<<30;
		For(i,n+1,n*2)
			dif=min(dif,a[i].fi-a[a[i].se+a[n].se?n:n-1].fi);
		ans3+=dif;
	}
	printf("%lld",min(min(ans1,ans2),ans3));
}