#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long mod = 1000000007;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const int N = 300100;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
map<int, pair<pair<long long, long long>, pair<long long, long long>>> m;
long long x[N], y[N];
map<int, pair<long long, long long>> dp;
long long dist(pair<long long, long long> a, pair<long long, long long> b) {
  return abs(a.first - b.first) + abs(a.second - b.second);
}
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    int aux = max(x[i], y[i]);
    if (!m.count(aux)) {
      m[aux].first = {x[i], y[i]};
      m[aux].second = {x[i], y[i]};
    }
    if (x[i] == aux) {
      m[aux].first.first = aux;
      m[aux].first.second = min(m[aux].first.second, y[i]);
      if (m[aux].second.second != aux) {
        m[aux].second.second = max(m[aux].second.second, y[i]);
      }
    }
    if (y[i] == aux) {
      m[aux].second.second = aux;
      m[aux].second.first = min(m[aux].second.first, x[i]);
      if (m[aux].first.first != aux) {
        m[aux].first.first = max(m[aux].first.first, x[i]);
      }
    }
  }
  int last = 0;
  m[0] = {{0, 0}, {0, 0}};
  dp[0] = {0, 0};
  for (auto p : m) {
    pair<long long, long long> a = m[last].first, b = m[last].second;
    pair<long long, long long> c = p.second.first, d = p.second.second;
    dp[p.first].first =
        min(dp[last].first + dist(a, d), dp[last].second + dist(b, d));
    dp[p.first].second =
        min(dp[last].first + dist(a, c), dp[last].second + dist(b, c));
    dp[p.first].first += dist(c, d);
    dp[p.first].second += dist(c, d);
    last = p.first;
  }
  cout << min(dp[last].first, dp[last].second) << "\n";
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  ;
  int t_ = 1;
  while (t_--) solve();
  return 0;
}
