#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long, long long> x, pair<long long, long long> y) {
  long long Max = max(x.first, x.second);
  if (x.second == Max && y.first == Max) return true;
  if (x.first == Max && y.second == Max) return false;
  if (x.second == Max && y.second == Max) {
    return x.first < y.first;
  }
  return x.second > y.second;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(8) << fixed;
  long long n;
  cin >> n;
  map<long long, vector<pair<long long, long long> > > arr;
  long long x, y;
  for (long long i = 0; i < n; ++i) {
    cin >> x >> y;
    arr[max(x, y)].push_back({x, y});
  }
  map<long long, long long> dists;
  for (auto &p : arr) {
    sort(p.second.begin(), p.second.end(), cmp);
    long long size = p.second.size();
    long long sum = 0;
    for (long long i = 1; i < size; ++i) {
      sum += abs(p.second[i].first - p.second[i - 1].first);
      sum += abs(p.second[i].second - p.second[i - 1].second);
    }
    dists[p.first] = sum;
  }
  const long long inf = 1e15;
  vector<vector<long long> > memo(n, vector<long long>(2, inf));
  long long level = 0;
  pair<long long, long long> prevBegin, prevEnd;
  for (auto &p : arr) {
    long long currDist = dists[p.first];
    if (level == 0) {
      memo[level][0] = currDist + p.second[0].first + p.second[0].second;
      memo[level][1] =
          currDist + p.second.back().first + p.second.back().second;
    } else {
      long long next = currDist + memo[level - 1][1] +
                       abs(prevBegin.first - p.second[0].first) +
                       abs(prevBegin.second - p.second[0].second);
      next = min(next, currDist + memo[level - 1][0] +
                           abs(prevEnd.first - p.second[0].first) +
                           abs(prevEnd.second - p.second[0].second));
      memo[level][0] = next;
      next = currDist + memo[level - 1][0] +
             abs(prevEnd.first - p.second.back().first) +
             abs(prevEnd.second - p.second.back().second);
      next = min(next, currDist + memo[level - 1][1] +
                           abs(prevBegin.first - p.second.back().first) +
                           abs(prevBegin.second - p.second.back().second));
      memo[level][1] = next;
    }
    level++;
    prevBegin = p.second[0];
    prevEnd = p.second.back();
  }
  cout << min(memo[level - 1][0], memo[level - 1][1]) << '\n';
  return 0;
}
