#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  long long x[N], y[N], far[N], to[N];
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
    far[i] = 9999999;
  }
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      far[i] = min(far[i], min(abs(x[i] - x[j]), abs(y[i] - y[j])));
      if (far[i] == min(abs(x[i] - x[j]), abs(y[i] - y[j]))) to[i] = j;
      far[j] = min(far[j], min(abs(x[i] - x[j]), abs(y[i] - y[j])));
      if (far[j] == min(abs(x[i] - x[j]), abs(y[i] - y[j]))) to[j] = i;
    }
  }
  for (int i = 0; i < N; i++) {
    sum += far[i];
    for (int j = i + 1; j < N; j++) {
      if (to[i] == j && to[j] == i) {
        sum -= far[i];
      }
    }
  }
  cout << sum << endl;
}
