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>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pl;
typedef vector<pl> vpl;
const int MN = 100100;
ll w[MN][2];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	ll n;
	cin >> n;
	vpl ord;
	for(int i=0;i<n;i++) {
		for(int j=0;j<2;j++) {
			cin >> w[i][j];
			ord.push_back({w[i][j],i});
		}
	}
	sort(ord.begin(),ord.end());
	ll su[2] = {0,0};
	for(int i=0;i<n;i++) {
		for(int j=0;j<2;j++) {
			su[j] += w[i][j];
		}
	}
	ll res = min(su[0],su[1]);
	ll miv = ord[n-1].first;
	bool wow = false;
	for(int i=0;i<n;i++) {
		ll wa = min(w[i][0],w[i][1]);
		ll wb = max(w[i][0],w[i][1]);
		if(wb <= ord[n-1].first && wa <= ord[n-2].first) {
			wow = true;break;
		}
	}
	ll saw = 0;
	for(int i=0;i<n;i++) {
		saw += ord[i].first;
	}
	if(wow) {
		res = min(res,saw);
	} else {
		for(int i=0;i<n;i++) {
			int id = n-1;
			for(;id>=0 && ord[id].second == i;id--) {
			}
			ll ma = max(w[i][0],w[i][1]);
			res = min(res,saw+ma-ord[id].first);
		}
	}
	cout << res << '\n';
}
