#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <utility>
#include <vector>
typedef unsigned int U;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
using std::cin; using std::cout;
using std::endl; using std::cerr;
using std::bitset; using std::map;
using std::queue; using std::priority_queue;
using std::set; using std::string;
using std::stringstream; using std::vector;
using std::pair; using std::make_pair;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<ULL, ULL> puu;
#ifdef DEBUG
#define pass cerr << "[" << __FUNCTION__ << "] : line = " << __LINE__ << endl;
#define display(x) cerr << #x << " = " << x << endl;
#define displaya(a, st, n) { cerr << #a << " = {"; \
      for(int qwq = (st); qwq <= (n); ++qwq) if(qwq == (st)) cerr << a[qwq]; else cerr << ", " << a[qwq];\
      cerr << "}" << endl; }
#define displayv(a) displaya(a, 0, (int)(a.size()-1))
#include <ctime>
class MyTimer {
  clock_t st;
public:
  MyTimer() { cerr << std::fixed << std::setprecision(0); reset(); }
  ~MyTimer() { report(); }
  void reset() { st = clock_t(); }
  void report() {  cerr << "Time consumed: " << (clock() - st) * 1e3 / CLOCKS_PER_SEC << "ms" << endl; }
} myTimer;
#else
#define pass ;
#define display(x) ;
#define displaya(a, st, n) {}
#define displayv(a) {}
class MyTimer {
public: void reset() {} void report() {}
} myTimer;
#endif

template<typename A, typename B>
std::ostream& operator << (std::ostream &cout, const pair<A, B> &x) {
  return cout << "(" << x.first << ", " << x.second << ")";
}
template<typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) { return a > b ? a = b, true : false; }
template<typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) { return a < b ? a = b, true : false; }
#ifdef QUICK_READ
char pool[1<<15|1],*it=pool+32768;
#define getchar() (it>=pool+32768?(pool[fread(pool,sizeof(char),1<<15,stdin)]=EOF,*((it=pool)++)):*(it++))
#endif
inline int readint() {
  int a = 0; char c = getchar(), p = 0;
  while(isspace(c)) c = getchar();
  if(c == '-') p = 1, c = getchar();
  while(isdigit(c)) a = a*10 + c - '0', c = getchar();
  return p ? -a : a;
}
inline LL readLL() {
  LL a = 0; char c = getchar(), p = 0;
  while(isspace(c)) c = getchar();
  if(c == '-') p = 1, c = getchar();
  while(isdigit(c)) a = a*10 + c - '0', c = getchar();
  return p ? -a : a;
}

const int maxN = 100000 + 233;
const int maxA = 1000000000 + 233;
int n;
int a[maxN], b[maxN], c[maxN];
bool vis[maxN];
int p1[maxN], p2[maxN];

LL corner() {
	LL sum = 0, ret;
	for(int i = 1; i <= n; ++i) sum += a[i];
	ret = sum;
	sum = 0;
	for(int i = 1; i <= n; ++i) sum += b[i];
	chmin(ret, sum);
	return ret;
}

int main() {
  std::ios::sync_with_stdio(false);
  cin >> n;
  for(int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
  LL ans = corner();
  vector<pii> v;
  v.reserve(2 * n);
  memset(p1, -1, sizeof(p1));
  memset(p2, -1, sizeof(p2));
  for(int i = 1; i <= n; ++i) v.emplace_back(a[i], i), v.emplace_back(b[i], i);
	std::sort(v.begin(), v.end());
	for(int i = 0; i < (int)v.size(); ++i) {
		if(p1[v[i].second] == -1) p1[v[i].second] = i;
		else p2[v[i].second] = i;
	}
	LL sum = 0;
	for(int i = 0; i < n; ++i) sum += v[i].first;
	displayv(v);
	for(int i = 1; i <= n; ++i) {
//		printf("%d %d\n", p1[i], p2[i]);
		if(p1[i] >= n - 2) chmin(ans, sum - v[n - 1].first - v[n - 2].first + a[i] + b[i]);
		else if(p2[i] >= n - 1) chmin(ans, sum - v[n - 1].first + std::max(a[i], b[i]));
		else chmin(ans, sum);
	}
	cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3456