#include <bits/stdc++.h>
typedef long long ll;
int a[100005], b[100005], app[200005];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", a + i, b + i);
		app[i << 1] = a[i];
		app[i << 1 | 1] = b[i];
	}
	std::sort(app, app + (n << 1));
	ll sa = 0, sb = 0, sum = 0;
	for (int i = 0; i < n; i++) {
		sa += a[i];
		sb += b[i];
		sum += app[i];
	}
	ll ans = std::min(sa, sb);
	for (int i = 0; i < n; i++) {
		int cur = n - 1;
		ll res = sum;
		if (a[i] < b[i]) {
			std::swap(a[i], b[i]);
		}
		if (a[i] > app[cur]) {
			res += a[i] - app[cur--];
		}
		if (b[i] > app[cur]) {
			res += b[i] - app[cur--];
		}
		ans = std::min(ans, res);
	}
	printf("%lld\n", ans);
	return 0;
}
