#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct data {
  int v, t;
} c[N << 1];
int n, a[N], b[N], cnt;
long long Ans;
bool cmp(data x, data y) { return x.v < y.v; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    c[++cnt] = (data){a[i], 0};
    c[++cnt] = (data){b[i], 1};
  }
  sort(c + 1, c + 1 + cnt, cmp);
  int s1 = 0, s2 = 0;
  for (int i = 1; i <= cnt; i++) {
    if (!c[i].t) {
      if (s2)
        Ans += c[i].v, s2--;
      else
        s1++;
    } else {
      if (s1)
        Ans += c[i].v, s1--;
      else
        s2++;
    }
  }
  Ans += n;
  cout << Ans << endl;
  return 0;
}
