#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long strToInt(string& a) {
  stringstream x(a);
  long long b;
  x >> b;
  return b;
}
void readI(long long& a) { cin >> a; }
void readI(long long& a, long long& b) { cin >> a >> b; }
void readI(long long& a, long long& b, long long& c) { cin >> a >> b >> c; }
vector<long long> readVI(long long n) {
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  return a;
}
vector<vector<long long> > readVVI(long long n, long long m) {
  vector<vector<long long> > a(n, vector<long long>(m));
  for (long long i = 0; i < n; i++) a[i] = readVI(m);
  return a;
}
vector<long long> readVLL(long long n) {
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  return a;
}
vector<vector<long long> > readVVLL(long long n, long long m) {
  vector<vector<long long> > a(n, vector<long long>(m));
  for (long long i = 0; i < n; i++) a[i] = readVLL(m);
  return a;
}
void print(vector<long long>& a) {
  for (auto el : a) {
    cout << el << ' ';
  }
  cout << '\n';
}
void print(vector<long long>& a, long long n) {
  long long cnt = 0;
  for (auto el : a) {
    if (cnt++ == n) break;
    cout << el << ' ';
  }
  cout << '\n';
}
const long long MOD = 1e9 + 7;
const long long INF = INT_MAX;
const long long INFF = 1e18;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long moveX[] = {-1, 0, 1, 0};
const long long moveY[] = {0, 1, 0, -1};
const long long N = 2e5 + 5;
bool customCmp(vector<long long>& a, vector<long long>& b) {
  if (a[0] == b[0]) return a[1] - a[0] < b[1] - b[0];
  return a[0] > b[0];
}
long long dis(vector<long long>& a, vector<long long>& b) {
  return abs(a[0] - b[0]) + abs(a[1] - b[1]);
}
void go() {
  long long n, big = 0, A, B;
  cin >> n;
  map<long long, vector<vector<long long> > > points;
  set<long long> val;
  points[0].push_back({0, 0});
  for (long long i = 0; i < n; i++) {
    long long a, b, c;
    cin >> a >> b;
    big = max(big, max(a, b));
    val.insert(max(a, b));
    points[max(a, b)].push_back({a, b});
  }
  for (auto i : val) sort(points[i].begin(), points[i].end(), customCmp);
  map<long long, vector<long long> > dp;
  vector<long long> tmp = {0, 0};
  dp[0] = tmp;
  for (auto el : val) dp[el] = tmp;
  long long last = 0, ans;
  for (auto i : val) {
    dp[i][0] = dis(points[i][0], points[i].back()) +
               min(dp[last][0] + dis(points[last][0], points[i].back()),
                   dp[last][1] + dis(points[last].back(), points[i].back()));
    dp[i][1] = dis(points[i][0], points[i].back()) +
               min(dp[last][0] + dis(points[last][0], points[i][0]),
                   dp[last][1] + dis(points[last].back(), points[i][0]));
    last = i;
    ans = min(dp[i][0], dp[i][1]);
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T = 1;
  while (T--) go();
  return 0;
}
