#include<bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
 
const int inf = 1e9;
const ll INF = 1e18;

const int mn = 1e5 + 10;
const ll mod = 1e9 + 7;

ll a[mn], b[mn], c[2 * mn];
ll pre[mn];
int main()
{
	int n;	scanf("%d", &n);
	ll tans1 = 0, tans2 = 0;
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld %lld", &a[i], &b[i]);
		tans1 += a[i], tans2 += b[i];
		c[i] = a[i], c[i + n] = b[i];
	}
	
	ll ans = min(tans1, tans2);
	
	sort(c + 1, c + 2 * n + 1);
	for (int i = 1; i <= n; i++)
		pre[i] = pre[i - 1] + c[i];
	for (int i = 1; i <= n; i++)
	{
		ll x = a[i], y = b[i];
		if (x > y)	swap(x, y);
		
		int p1 = lower_bound(c + 1, c + 2 * n + 1, x) - c;
		int p2 = lower_bound(c + 1, c + 2 * n + 1, y) - c;
		
		if (p1 > n && p2 > n)
			ans = min(ans, x + y + pre[n - 2]);
		else if (p1 <= n && p2 > n)
			ans = min(ans, pre[n - 1] + y);
		else if (p1 <= n && p2 <= n)
			ans = min(ans, pre[n]);
	}
	printf("%lld\n", ans);
	
	return 0;
}
