#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 6;
const long long INF = 1e15 + 6;
pair<int, int> a[MAX_N];
int main() {
  int n;
  scanf("%d", &n);
  vector<long long> va, vb;
  for (int i = 1; n >= i; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    a[i] = make_pair(x, y);
    va.push_back(x);
    vb.push_back(y);
  }
  va.push_back(-INF);
  va.push_back(INF);
  vb.push_back(-INF);
  vb.push_back(INF);
  sort(va.begin(), va.end());
  sort(vb.begin(), vb.end());
  long long ans = 0;
  long long kirino = INF;
  for (int i = 1; n >= i; i++) {
    long long _ = a[i].first, __ = a[i].second;
    int posa = lower_bound(va.begin(), va.end(), a[i].first) - va.begin();
    int posb = lower_bound(vb.begin(), vb.end(), a[i].second) - vb.begin();
    ans += min(min(abs(va[posa + 1] - _), abs(va[posa - 1] - _)),
               min(abs(vb[posb + 1] - __), abs(vb[posb - 1] - __)));
    kirino =
        min(kirino, min(min(abs(va[posa + 1] - _), abs(va[posa - 1] - _)),
                        min(abs(vb[posb + 1] - __), abs(vb[posb - 1] - __))));
  }
  printf("%lld\n", ans - kirino);
}
