#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2e5+5;
int n,id[N];long long sum,ans;
pair<int,int>a[N];
int main(){
	scanf("%d",&n);
	for(int i=1,x,y;i<=n;++i){
		scanf("%d%d",&x,&y);
		ans+=x;sum+=y;
		a[i]={x,i};a[i+n]={y,i+n};
	}
	ans=min(ans,sum);sum=0;
	sort(a+1,a+n+n+1);
	for(int i=1;i<=n+n;++i)id[a[i].second]=i;
	for(int i=1;i<=n;++i)sum+=a[i].first;
	for(int i=1;i<=n;++i){
		int x=id[i],y=id[i+n];
		if(x>y)swap(x,y);
		if(y<=n)ans=min(ans,sum);
		else if(x<n)ans=min(ans,sum-a[n].first+a[y].first);
		else ans=min(ans,sum-a[n].first-a[n-1].first+a[x].first+a[y].first);
	}
	printf("%lld\n",ans);
	return 0;
}
