#include <bits/stdc++.h>
using namespace std;
typedef struct {
  long long from, to;
} T;
int main() {
  long long N;
  scanf("%lld", &N);
  long long city[100000][2];
  vector<T> vec;
  for (int i = 0; i < N; i++) {
    scanf("%lld %lld", &city[i][0], &city[i][1]);
  }
  long long total = 0;
  for (int i = 0; i < N - 1; i++) {
    long long a[2] = {city[i][0], city[i][1]};
    int idx;
    long long min_t = 1000000008;
    for (int j = 0; j < N; j++) {
      if (i == j) continue;
      long long min;
      long long x = abs(a[0] - city[j][0]);
      long long y = abs(a[1] - city[j][1]);
      if (x < y) {
        min = x;
      } else {
        min = y;
      }
      if (min_t > min) {
        int flag = 1;
        for (int k = 0; k < vec.size(); k++) {
          if (vec.at(k).from == j && vec.at(k).to == i) flag = 0;
        }
        if (flag) {
          idx = j;
          min_t = min;
        }
      }
    }
    total += min_t;
    T hoge;
    hoge.from = i;
    hoge.to = idx;
    vec.push_back(hoge);
  }
  printf("%lld\n", total);
  return 0;
}
