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<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 100000
#define LL long long
using namespace std;
int n,a[N+5],b[N+5],p[N+5],q[N+5];
struct Data
{
	int p,v;I Data(CI x=0,CI y=0):p(x),v(y){}
	I bool operator < (Con Data& o) Con {return v<o.v;}
}s[2*N+5];
int main()
{
	RI i;LL A=0,B=0;for(scanf("%d",&n),i=1;i<=n;++i)
		scanf("%d%d",a+i,b+i),s[i]=Data(i,a[i]),s[n+i]=Data(n+i,b[i]),A+=a[i],B+=b[i];
	for(sort(s+1,s+2*n+1),i=1;i<=2*n;++i) s[i].p<=n?p[s[i].p]=i:q[s[i].p-n]=i;
	LL ans=min(A,B),t=0,g;for(i=1;i<=n;++i) t+=s[i].v;
	for(i=1;i<=n;++i) p[i]>q[i]&&(swap(p[i],q[i]),0),g=t,
		p[i]<=n&&(g+=s[n+1].v-s[p[i]].v),q[i]<=n+1&&(g+=s[n+2].v-s[q[i]].v),ans=min(ans,g);
	return printf("%lld\n",ans),0;
}