#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
};
int x[200010], y[200010], id[200010][2];
long long dp[200010][2];
vector<node> vec;
int N, M;
long long dis(int a, int b) {
  return abs(vec[a].x - vec[b].x) + abs(vec[a].y - vec[b].y);
}
bool cmp(node a, node b) { return max(a.x, a.y) < max(b.x, b.y); }
int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  vec.push_back((node){0, 0});
  for (int i = 1; i <= N; ++i) {
    cin >> x[i] >> y[i];
    vec.push_back((node){x[i], y[i]});
  }
  sort(vec.begin(), vec.end(), cmp);
  int pre = max(vec[1].x, vec[1].y), minx = 1, miny = 1;
  for (int i = 2; i <= N; ++i) {
    if (max(vec[i].x, vec[i].y) == pre) {
      if (vec[i].x < vec[minx].x)
        minx = i;
      else if (vec[i].x == vec[minx].x && vec[i].y > vec[minx].y)
        minx = i;
      if (vec[i].y < vec[miny].y)
        miny = i;
      else if (vec[i].y == vec[miny].y && vec[i].x > vec[miny].x)
        miny = i;
    } else {
      ++M;
      id[M][0] = minx;
      id[M][1] = miny;
      pre = max(vec[i].x, vec[i].y);
      minx = miny = i;
    }
  }
  ++M;
  id[M][0] = minx;
  id[M][1] = miny;
  for (int i = 1; i <= M; ++i) {
    dp[i][0] = min(dp[i - 1][0] + dis(id[i - 1][0], id[i][1]),
                   dp[i - 1][1] + dis(id[i - 1][1], id[i][1])) +
               dis(id[i][0], id[i][1]);
    dp[i][1] = min(dp[i - 1][0] + dis(id[i - 1][0], id[i][0]),
                   dp[i - 1][1] + dis(id[i - 1][1], id[i][0])) +
               dis(id[i][0], id[i][1]);
  }
  cout << min(dp[M][0], dp[M][1]) << endl;
  return 0;
}
