#include <algorithm>
#include <cstdio>
using ll = long long;
int a[100005], b[100005], app[200005];
int main()
{
	// freopen("AGC028-C.in", "r", stdin);
	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];
	}
	ll sum_a = 0, sum_b = 0, sum = 0;
	std::sort(app, app + (n << 1));
	for (int i = 0; i < n; i++)
	{
		sum += app[i];
		sum_a += a[i];
		sum_b += b[i];
	}
	ll ans = std::min(sum_a, sum_b);
	for (int i = 0; i < n; i++)
	{
		int pos = n - 1;
		ll res = sum;
		if (std::max(a[i], b[i]) > app[pos])
			res += std::max(a[i], b[i]) - app[pos--];
		if (std::min(a[i], b[i]) > app[pos])
			res += std::min(a[i], b[i]) - app[pos--];
		ans = std::min(ans, res);
	}
	printf("%lld\n", ans);
	return 0;
}
