#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL N=100010;
LL n, a[N], b[N], s[N<<1],f[N<<1];
int main(){
	scanf("%lld",&n);
	for(LL i=1; i<=n; ++i)scanf("%lld%lld",&a[i],&b[i]),s[i*2-1]=a[i],s[i*2]=b[i];
	sort(s+1,s+2*n+1);
	for(LL i=1; i<=n; ++i)f[i]=f[i-1]+s[i];
	LL ans=0, tmp=0;
	for(LL i=1; i<=n; ++i)ans+=a[i];
	for(LL i=1; i<=n; ++i)tmp+=b[i]; ans=min(ans,tmp);
	for(LL i=1; i<=n; ++i){
		tmp=a[i]+b[i]+f[n-2];
		LL d=n-2;
		if(a[i]>b[i])swap(a[i],b[i]);
		if(s[d]>=a[i])++d,tmp=tmp-a[i]+s[d];
		if(s[d]>=b[i])++d,tmp=tmp-b[i]+s[d];
		ans=min(ans,tmp);
	}
	printf("%lld",ans);
	return 0;
}