#include <bits/stdc++.h>
using namespace std;
const int maxn = 200007;
struct pp {
  int x, y;
} A[maxn];
bool operator<(const pp &x, const pp &y) {
  if (x.x ^ y.x) return x.x < y.x;
  return x.y > y.y;
}
long long operator-(const pp &x, const pp &y) {
  return 0ll + abs(x.x - y.x) + abs(x.y - y.y);
}
vector<pp> m[maxn];
int d[maxn], id[maxn];
long long dis[maxn], f[maxn][2];
int N;
int main() {
  scanf("%d", &N);
  pp t;
  for (int i = 1; i <= N; i++) {
    scanf("%d%d", &t.x, &t.y);
    d[i] = max(t.x, t.y);
    A[i] = t;
  }
  sort(d + 1, d + 1 + N);
  int tot = unique(d + 1, d + 1 + N) - d - 1;
  for (int i = 1; i <= N; i++)
    id[i] = lower_bound(d + 1, d + 1 + tot, max(A[i].x, A[i].y)) - d,
    m[id[i]].push_back(A[i]);
  for (int i = 1; i <= tot; i++) {
    sort(m[i].begin(), m[i].end());
    for (int k = 1; k < m[i].size(); k++) dis[i] += m[i][k] - m[i][k - 1];
  }
  t.x = t.y = 0;
  long long d1, d2;
  m[0].push_back(t);
  for (int i = 1; i <= tot; i++) {
    f[i][0] = min(f[i - 1][0] + (m[i][m[i].size() - 1] - m[i - 1][0]),
                  f[i - 1][1] +
                      (m[i][m[i].size() - 1] - m[i - 1][m[i - 1].size() - 1])) +
              dis[i];
    f[i][1] = min(f[i - 1][0] + (m[i][0] - m[i - 1][0]),
                  f[i - 1][1] + (m[i][0] - m[i - 1][m[i - 1].size() - 1])) +
              dis[i];
  }
  printf("%lld", min(f[tot][0], f[tot][1]));
  return 0;
}
