#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int> > q, g;
int myabs(int x) {
  if (x < 0)
    return -x;
  else
    return x;
}
int main() {
  int n, i, tx, ty, px, py, ans1 = 0, ans2 = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    q.push(make_pair(x, y));
    g.push(make_pair(y, x));
  }
  pair<int, int> t;
  t = q.top();
  q.pop();
  tx = t.first;
  ty = t.second;
  for (i = 2; i <= n; i++) {
    t = q.top();
    q.pop();
    px = t.first;
    py = t.second;
    ans1 += min(myabs(px - tx), myabs(py - ty));
    tx = px;
    ty = py;
  }
  t = g.top();
  g.pop();
  tx = t.first;
  ty = t.second;
  for (i = 2; i <= n; i++) {
    t = g.top();
    g.pop();
    px = t.first;
    py = t.second;
    ans2 += min(myabs(px - tx), myabs(py - ty));
    tx = px;
    ty = py;
  }
  printf("%d\n", min(ans1, ans2));
  return 0;
}
