#include <bits/stdc++.h>
using namespace std;
long long i, j, k, l, n, q, m, d, su, sx, sy,
    prod = 1, ans, maxi, a, b, x, y, o, e, f, mini = 10000000000000, t, cnt;
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int ti = 1;
  while (ti--) {
    cin >> n;
    map<long long, pair<long long, long long> > dpx, dpy;
    set<long long> se;
    long long dp1 = 0, dp2 = 0;
    for (long long i = 0; i < n; i++) {
      cin >> x >> y;
      if (dpx.find(max(x, y)) != dpx.end()) {
        if (x < dpx[max(x, y)].first)
          dpx[max(x, y)] = {x, y};
        else if (x == dpx[max(x, y)].first)
          dpx[max(x, y)] = {x, max(y, dpx[max(x, y)].second)};
      } else
        dpx[max(x, y)] = {x, y};
      if (dpy.find(max(x, y)) != dpy.end()) {
        if (y < dpy[max(x, y)].second)
          dpy[max(x, y)] = {x, y};
        else if (y == dpy[max(x, y)].second)
          dpy[max(x, y)] = {max(x, dpy[max(x, y)].first), y};
      } else
        dpy[max(x, y)] = {x, y};
      se.insert(max(x, y));
    }
    long long prex1 = 0, prey1 = 0, prex2 = 0, prey2 = 0;
    for (auto i : se) {
      long long temp1, temp2;
      temp1 = temp2 =
          abs(dpy[i].first - dpx[i].first) + abs(dpy[i].second - dpx[i].second);
      temp2 +=
          min(abs(dpx[i].first - prex2) + abs(dpx[i].second - prey2) + dp2,
              abs(dpx[i].first - prex1) + abs(dpx[i].second - prey1) + dp1);
      temp1 +=
          min(abs(dpy[i].first - prex2) + abs(dpy[i].second - prey2) + dp2,
              abs(dpy[i].first - prex1) + abs(dpy[i].second - prey1) + dp1);
      dp2 = temp2;
      dp1 = temp1;
      prex1 = dpx[i].first;
      prex2 = dpy[i].first;
      prey1 = dpx[i].second;
      prey2 = dpy[i].second;
    }
    cout << min(dp2, dp1);
  }
  return 0;
}
