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 rg register
typedef long long LL;
const int maxn = 1000010;
const int inf = 1 << 30;

inline LL read() {
	register char ch;
	while(!isdigit(ch = getchar()));
	register LL x = ch ^ '0';
	while(isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^ '0');
	return x;
}

LL n;
LL ans1 = 0, ans2 = 0;
LL a[maxn], b[maxn], c[maxn << 1], pre[maxn];

int main() {
	n = read();
	ans1 = 0, ans2 = 0;
	for(rg int i = 1; i <= n; ++i) a[i] = read(), b[i] = read();
	for(rg int i = 1; i <= n; ++i) ans1 += a[i], ans2 += b[i];
	ans1 = std::min(ans1, ans2);
	for(rg int i = 1; i <= n; ++i) c[i * 2] = a[i], c[i * 2 - 1] = b[i];
	std::sort(c + 1, c + 2 * n + 1);
	for(rg int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + c[i];
	for(rg int i = 1; i <= n; ++i) {
		ans2 = 0;
		int now = n;
		if(a[i] >= c[now]) ans2 += a[i], now--;
		if(b[i] >= c[now]) ans2 += b[i], now--;
		ans1 = std::min(ans1, ans2 + pre[now]);
	}
	printf("%lld\n", ans1);
	return 0;
}