#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 100000
#define LL long long
using namespace std;
int n,a[N+5],b[N+5],p[N+5],q[N+5];
struct Data
{
	int p,v;I Data(CI x=0,CI y=0):p(x),v(y){}
	I bool operator < (Con Data& o) Con {return v<o.v;}
}s[2*N+5];
int main()
{
	RI i;LL A=0,B=0;for(scanf("%d",&n),i=1;i<=n;++i)
		scanf("%d%d",a+i,b+i),s[i]=Data(i,a[i]),s[n+i]=Data(n+i,b[i]),A+=a[i],B+=b[i];
	for(sort(s+1,s+2*n+1),i=1;i<=2*n;++i) s[i].p<=n?p[s[i].p]=i:q[s[i].p-n]=i;
	LL ans=min(A,B),t=0,g;for(i=1;i<=n;++i) t+=s[i].v;
	for(i=1;i<=n;++i) p[i]>q[i]&&(swap(p[i],q[i]),0),g=t,
		p[i]<=n&&(g+=s[n+1].v-s[p[i]].v),q[i]<=n+1&&(g+=s[n+2].v-s[q[i]].v),ans=min(ans,g);
	return printf("%lld\n",ans),0;
}