#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
list<long long int> Prime(int M) {
  list<long long int> P;
  P.push_back(2);
  P.push_back(3);
  for (int i = 5; i <= M; i += 6) {
    bool flag = true;
    for (auto j : P) {
      if (i % j == 0) {
        flag = false;
        break;
      }
    }
    if (flag) P.push_back(i);
    flag = true;
    for (auto j : P) {
      if ((i + 2) % j == 0) {
        flag = false;
        break;
      }
    }
    if (flag) P.push_back(i + 2);
  }
  return P;
}
long long int power(long long int x, long long int n, long long int M) {
  long long int tmp = 1;
  if (n > 0) {
    tmp = power(x, n / 2, M);
    if (n % 2 == 0)
      tmp = (tmp * tmp) % M;
    else
      tmp = (((tmp * tmp) % M) * x) % M;
  }
  return tmp;
}
long long int N, M, K, Q, W, H;
long long int ans;
int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  long long int x[100000];
  long long int y[100000];
  long long int box_x[100000];
  long long int box_y[100000];
  long long int dis_x[100000];
  long long int dis_y[100000];
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
    box_x[i] = x[i] * MOD + i;
    box_y[i] = y[i] * MOD + i;
  }
  sort(box_x, box_x + N);
  sort(box_y, box_y + N);
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      dis_x[box_x[i] % MOD] = box_x[i + 1] / MOD - box_x[i] / MOD;
      dis_y[box_y[i] % MOD] = box_y[i + 1] / MOD - box_y[i] / MOD;
      continue;
    }
    if (i == N - 1) {
      dis_x[box_x[i] % MOD] = box_x[i] / MOD - box_x[i - 1] / MOD;
      dis_y[box_y[i] % MOD] = box_y[i] / MOD - box_y[i - 1] / MOD;
      continue;
    }
    dis_x[box_x[i] % MOD] = box_x[i + 1] / MOD - box_x[i] / MOD;
    dis_y[box_y[i] % MOD] = box_y[i + 1] / MOD - box_y[i] / MOD;
    dis_x[box_x[i] % MOD] =
        min(dis_x[box_x[i] % MOD], box_x[i] / MOD - box_x[i - 1] / MOD);
    dis_y[box_y[i] % MOD] =
        min(dis_y[box_y[i] % MOD], box_y[i] / MOD - box_y[i - 1] / MOD);
  }
  long long int ma = LLONG_MAX;
  for (int i = 0; i < N; i++) {
    ma = min(ma, min(dis_x[i], dis_y[i]));
    ans += min(dis_x[i], dis_y[i]);
  }
  ans -= ma;
  cout << ans << endl;
  return 0;
}
