#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define LL long long
#define F first
#define S second
 
int n;
LL ans;
LL sum1,sum2;
bool ok[N];
vector<pii> v;
 
int main()
{
	
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x,y;
		cin>>x>>y;
		sum1+=x; sum2+=y;
		v.pb(mp(x,i)); v.pb(mp(y,i));
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++)
		ans+=v[i].F;
	for(int i=0;i<n;i++)
	{
		if(ok[v[i].S]) return cout<<ans<<'\n',0;
		ok[v[i].S]=1;
	}
	cout<<min(min(sum1,sum2),ans-v[n-1].F+((v[n-1].S!=v[n].S)?v[n].F:min(v[n+1].F,v[n-1].F-v[n-2].F+v[n].F)))<<'\n';
	
	return 0;
}