#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
const int N = 5e5 + 5, inf = 1e9 + 7;
ll dp[N][2];
pi a[N];
int main() {
  ios ::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second;
  auto cmp = [&](pi a, pi b) {
    if (max(a.first, a.second) == max(b.first, b.second)) return a < b;
    return max(a.first, a.second) < max(b.first, b.second);
  };
  sort(a + 1, a + 1 + n, cmp);
  pi la = {0, 0}, lb = {0, 0};
  for (int i = 1; i <= n; ++i) {
    int j = i, level = max(a[i].first, a[i].second);
    while (max(a[j].first, a[j].second) == level) ++j;
    --j;
    pi b = a[j];
    int k = j;
    while (k >= i && a[k].first == level) b = a[k], k--;
    if (a[i].second != level) {
      b = a[j];
      swap(a[i], b);
    }
    ll dist = abs(a[i].first - b.first) + abs(a[i].second - b.second);
    dp[j][0] = dp[i - 1][1] + abs(lb.first - b.first) +
               abs(lb.second - b.second) + dist;
    dp[j][0] = min(dp[j][0], dp[i - 1][0] + abs(la.first - b.first) +
                                 abs(la.second - b.second) + dist);
    dp[j][1] = dp[i - 1][0] + abs(la.first - a[i].first) +
               abs(la.second - a[i].second) + dist;
    dp[j][1] = min(dp[j][1], dp[i - 1][1] + abs(lb.first - a[i].first) +
                                 abs(lb.second - a[i].second) + dist);
    la = a[i], lb = b;
    i = j;
  }
  cout << min(dp[n][0], dp[n][1]);
  return 0;
}
