#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<
                                    !is_same<T_container, string>::value,
                                    typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v) {
  os << '{';
  string sep;
  for (const T &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
const long long mxn = 1e5;
const long long INF = 2e18;
const int32_t M = 1000000007;
const long double pie = acos(-1);
void solve_LOG() {
  long long n;
  cin >> n;
  set<pair<long long, long long>, greater<pair<long long, long long>>> l, r;
  vector<long long> a(n + 1), b(n + 1);
  for (long long i = 1; i <= n; i++) {
    long long x, y;
    cin >> x >> y;
    l.insert({x, i});
    r.insert({y, i});
    a[i] = x;
    b[i] = y;
  }
  long long cost = 0;
  while (((long long)(l).size()) > 1 && ((long long)(r).size()) > 1) {
    assert(((long long)(l).size()) == ((long long)(r).size()));
    auto il = l.begin();
    auto ir = r.begin();
    ;
    long long idl = (*il).second;
    long long idr = (*ir).second;
    long long x = (*il).first;
    long long y = (*ir).first;
    if (idl == idr) {
      cost += 1 + max(x, y);
      l.erase(il);
      r.erase(ir);
      continue;
    }
    idl = (*il).second;
    idr = (*ir).second;
    x = (*il).first;
    y = (*ir).first;
    ;
    cost += max(x, y) + 1;
    long long new_id = min(idl, idr);
    long long new_left = a[idr];
    assert(b[idr] == y);
    long long new_right = b[idl];
    assert(a[idl] == x);
    l.erase({a[idl], idl});
    l.erase({a[idr], idr});
    r.erase({b[idl], idl});
    r.erase({b[idr], idr});
    a[new_id] = new_left;
    b[new_id] = new_right;
    l.insert({new_left, new_id});
    r.insert({new_right, new_id});
  }
  cost += max((*l.begin()).first, (*r.begin()).first) + 1;
  cout << cost;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long _t = 1;
  for (long long i = 1; i <= _t; i++) {
    solve_LOG();
  }
  return 0;
}
