We have a directed weighted graph with N vertices. Each vertex has two integers written on it, and the integers written on Vertex i are A_i and B_i.

In this graph, there is an edge from Vertex x to Vertex y for all pairs 1 \leq x,y \leq N, and its weight is {\rm min}(A_x,B_y).

We will consider a directed cycle in this graph that visits every vertex exactly once. Find the minimum total weight of the edges in such a cycle.

Constraints

* 2 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N
A_1 B_1
A_2 B_2
:
A_N B_N


Output

Print the minimum total weight of the edges in such a cycle.

Examples

Input

3
1 5
4 2
6 3


Output

7


Input

4
1 5
2 6
3 7
4 8


Output

10


Input

6
19 92
64 64
78 48
57 33
73 6
95 73


Output

227
#include<iostream>
#include<cstdio>
#include<algorithm>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=200200;
int n,m,x,y,mx,b[N],c[2];
long long su;
struct ele{
	int w,i,c;
	ele(int _w=0,int _i=0,int _c=0){w=_w,i=_i,c=_c;}
	bool operator < (const ele&a)const{return w<a.w;}
}q[N];
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d",&n);m=n<<1;
	FOR(i,1,n) scanf("%d%d",&x,&y),q[i]=ele(x,i,0),q[i+n]=ele(y,i,1);
	sort(q+1,q+m+1);
	FOR(i,1,n) mx=max(mx,++b[q[i].i]),su+=q[i].w,c[q[i].c]++;
	if(mx==2 || !c[0] || !c[1]) cout<<su<<'\n';
	else if(q[n].i!=q[n+1].i || c[q[n].c]==1) cout<<su-q[n].w+q[n+1].w<<'\n';
	else cout<<min(su-q[n].w+q[n+2].w,su-q[n-1].w+q[n+1].w)<<'\n';
}