#include <bits/stdc++.h>
#define M 1000005
#define FI first
#define SE second
#define MP std::make_pair
#define PB push_back
typedef long long ll;
int n;
std::pair <int,int> S[M];
bool vis[M];
int read(){
	char c=getchar();int ans=0;
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9') ans=ans*10+c-'0',c=getchar();
	return ans;
}
void Write(ll x){
	if (x<10) putchar(x^48);
	else Write(x/10),putchar((x%10)^48);
	return;
}
ll min(ll x,ll y){return x<y?x:y;}
bool check(){
	int flag1=0,flag2=0;
	for (int i=1;i<=n;i++)
		if (vis[i]&&vis[i+n]) return 1;
	for (int i=1;i<=n;i++)
		flag1|=vis[i],flag2|=vis[i+n];
	return flag1^flag2;
}
int main(){
	n=read();
	for (int i=1;i<=n;i++) S[i*2-1].FI=read(),S[i*2-1].SE=i,S[i*2].FI=read(),S[i*2].SE=i+n;
	std::sort(S+1,S+1+n*2);ll sum=0;
	for (int i=1;i<=n;i++) vis[S[i].SE]=1,sum+=S[i].FI;
	if (check()) return Write(sum),0;
	vis[S[n].SE]=0,vis[S[n+1].SE]=1;
	if (check()) return Write(sum-S[n].FI+S[n+1].FI),0;
	Write(min(sum-S[n-1].FI+S[n+1].FI,sum-S[n].FI+S[n+2].FI));
	return 0;
}
