#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int x, y;
  int xmin = 10000;
  int ymin = 10000;
  int a[10000];
  int b[10000];
  int c[10000] = {100};
  int d[10000] = {100};
  cin >> n;
  int i, j;
  int sum = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for (i = 1; i < n; i++) {
    c[i] = 1000;
    d[i] = 1000;
  }
  for (i = 0; i < n - 1; i++) {
    for (j = 0; j < n; j++) {
      xmin = abs(a[i] - a[j]);
      ymin = abs(b[i] - b[j]);
      if (xmin < c[i] && i != j) {
        c[i] = xmin;
      }
      if (ymin < d[i] && i != j) {
        d[i] = ymin;
      }
    }
  }
  for (i = 0; i < n - 1; i++) {
    if (c[i] < d[i]) {
      sum = sum + c[i];
    } else {
      sum = sum + d[i];
    }
  }
  cout << sum;
  return 0;
}
