#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double pi = acos(-1);
int n, i, j, k, t;
pair<int, int> a[100002];
int main() {
  scanf("%d", &n);
  for (i = 0; i < n; ++i) scanf("%d %d", &a[i].first, &a[i].second);
  long long ans = n;
  multiset<pair<int, int> > p, q;
  for (i = 0; i < n; ++i) {
    if (a[i].second == 0 && a[i].first == 0) continue;
    p.insert({a[i].first, a[i].second});
    q.insert({a[i].second, a[i].first});
  }
  while (p.size() > 1) {
    int l = 0, r = 0;
    pair<int, int> tmp1 = *p.rbegin();
    q.erase(q.lower_bound({tmp1.second, tmp1.first}));
    p.erase(--p.end());
    pair<int, int> tmp2 = *q.rbegin();
    p.erase(p.lower_bound({tmp2.second, tmp2.first}));
    q.erase(--q.end());
    if (max(tmp1.first, tmp1.second) + max(tmp2.first, tmp2.second) >=
        max(tmp1.first, tmp2.first) + max(tmp1.second, tmp2.second)) {
      l = tmp2.second;
      r = tmp1.second;
      ans += max(tmp1.first, tmp2.first);
    } else {
      if (max(tmp1.first, tmp1.second) > max(tmp2.first, tmp2.second)) {
        l = tmp2.second;
        r = tmp2.first;
        ans += max(tmp1.first, tmp1.second);
      } else {
        l = tmp1.first;
        r = tmp1.second;
        ans += max(tmp2.first, tmp2.second);
      }
    }
    if (l || r) {
      p.insert({l, r});
      q.insert({r, l});
    }
  }
  if (!p.empty()) {
    ans += max(p.begin()->first, p.begin()->second);
  }
  printf("%lld\n", ans);
  return 0;
}
