#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n;
vector<pair<long,int> >a;
int cnt[1<<17];
int main()
{
	cin>>n;
	for(int i=0;i<2*n;i++)
	{
		int x;cin>>x;
		a.push_back(make_pair(x,i));
	}
	int f=3,u=0;
	sort(a.begin(),a.end());
	long ans=0;
	for(int i=0;i<n;i++)
	{
		ans+=a[i].first;
		u+=cnt[a[i].second/2]++;
		f&=2-a[i].second%2;
	}
	if(f)cout<<ans<<endl;
	else if(u)cout<<ans<<endl;
	else
	{
		if(a[n-1].second/2!=a[n].second/2)
		{
			cout<<ans-a[n-1].first+a[n].first<<endl;
		}
		else
		{
			cout<<ans+min(a[n+1].first-a[n-1].first,a[n].first-a[n-2].first)<<endl;
		}
	}
}