#include <bits/stdc++.h>
using namespace std;
inline char get(void) {
  static char buf[100000], *S = buf, *T = buf;
  if (S == T) {
    T = (S = buf) + fread(buf, 1, 100000, stdin);
    if (T == S) return EOF;
  }
  return *S++;
}
inline void read(int& x) {
  static char c;
  x = 0;
  for (c = get(); c < '0' || c > '9'; c = get())
    ;
  for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
}
const int M = 200 * 1000 + 10;
int n;
vector<pair<int, int> > ipt(M);
vector<pair<int, int> > range(M);
set<int> appear;
int app[M];
int tp;
int gt(int x) {
  int lo = 0, hi = tp - 1;
  int mid = (hi + lo) >> 1;
  while (lo < hi) {
    if (x > app[mid])
      lo = mid + 1;
    else
      hi = mid;
    mid = (hi + lo) >> 1;
  }
  return lo;
}
int ma = 1000 * 1000 * 1000;
int up = ma << 1;
long long cal(int a, int b, int level, int pre) {
  int xa, xb, ya, yb;
  if (pre >= a)
    xa = a, ya = pre;
  else
    ya = up - a, xa = pre;
  if (level >= b)
    xb = b, yb = level;
  else
    yb = up - b, xb = level;
  return abs(xa - xb) + abs(ya - yb);
}
int main() {
  read(n);
  for (int i = 0; i < n; ++i) {
    read(ipt[i].first), read(ipt[i].second);
    appear.insert(max(ipt[i].first, ipt[i].second));
  }
  auto it = appear.begin();
  tp = 0;
  while (it != appear.end()) app[tp++] = *it++;
  for (int i = 0; i < tp; ++i)
    range[i].first = 0x3f3f3f3f * 2, range[i].second = 0;
  for (int i = 0; i < n; ++i) {
    int x = ipt[i].first, y = ipt[i].second;
    int tt = max(x, y);
    int id = gt(tt);
    if (x > y) {
      range[id].first = min(range[id].first, up - y);
      range[id].second = max(range[id].second, up - y);
    } else {
      range[id].first = min(range[id].first, x);
      range[id].second = max(range[id].second, x);
    }
  }
  long long lf = 0, ri = 0;
  long long nl, nr;
  int pl = 0, pr = up;
  int pre = 0;
  for (int i = 0; i < tp; ++i) {
    int tl = range[i].first, tr = range[i].second;
    long long dis = cal(tl, tr, app[i], app[i]);
    long long l_l = cal(pl, tl, app[i], pre), r_l = cal(pr, tl, app[i], pre);
    long long l_r = cal(pl, tr, app[i], pre), r_r = cal(pr, tr, app[i], pre);
    ri += dis, lf += dis;
    nr = min(l_l + lf, r_l + ri);
    nl = min(r_r + ri, l_r + lf);
    ri = nr, lf = nl;
    pl = tl, pr = tr;
    pre = app[i];
  }
  cout << min(lf, ri) << endl;
  return 0;
}
