#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> X(N), Y(N), town(N);
  vector<bool> used(N);
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    X[i] = make_pair(x, i);
    Y[i] = make_pair(y, i);
    town[i] = make_pair(x, y);
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  vector<int> dist(N);
  long long ans = 0;
  for (int i = 0; i < N - 1; i++) {
    int mind = 1e9 + 1;
    ;
    if (i < N - 1) {
      int d = X[i + 1].first - X[i].first;
      if (d < mind) {
        dist[X[i].second] = X[i + 1].second;
        mind = d;
      }
    }
  }
  for (int i = 0; i < N - 1; i++) {
    int mind = 1e9 + 1;
    ;
    int target = -1;
    if (i < N - 1) {
      int d = Y[i + 1].first - Y[i].first;
      if (d < mind) {
        target = Y[i + 1].second;
        mind = d;
      }
    }
    if (abs(town[Y[i].second].first - town[dist[Y[i].second]].first) > mind) {
      if (dist[target] != Y[i].second) {
        dist[Y[i].second] = target;
      }
    }
  }
  int maxd = 0;
  vector<int> cnt(N);
  for (int i = 0; i < N; i++) {
    int d = min(abs(town[i].first - town[dist[i]].first),
                abs(town[i].second - town[dist[i]].second));
    ans += d;
    cnt[i]++;
    cnt[dist[i]]++;
  }
  for (int i = 0; i < N; i++) {
    int d = min(abs(town[i].first - town[dist[i]].first),
                abs(town[i].second - town[dist[i]].second));
    if (cnt[i] >= 2 && cnt[dist[i]] >= 2) {
      maxd = max(maxd, d);
    }
  }
  cout << ans - maxd << endl;
  return 0;
}
