#include<bits/stdc++.h>
using namespace std;
const int N=3e5+1;
long long n,a[N],b[N],A,B,s,v[N];
pair<int,int>p[N];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		p[i].first=a[i],p[i+n].first=b[i];
		p[i].second=i,p[i+n].second=i+n;
		A+=a[i],B+=b[i];
	}
	sort(p+1,p+2*n+1);
	for(int i=1;i<=n-2;i++)
		s+=p[i].first,v[p[i].second]=1;
	A=min(A,B);
	for(int i=1;i<=n;i++)
		if(v[i]+v[i+n]==2)
			A=min(A,s+p[n-1].first+p[n].first);
		else if(v[i]+v[i+n]==1)
			if(p[n-1].second==i||p[n-1].second==i+n)
				A=min(A,s+p[n].first+a[i]*(1-v[i])+b[i]*(1-v[i+n]));
			else
				A=min(A,s+p[n-1].first+a[i]*(1-v[i])+b[i]*(1-v[i+n]));
		else
			A=min(A,s+a[i]+b[i]);
	cout<<A;
	return 0;
}