#include <bits/stdc++.h>
using namespace std;
struct A {
  int from, to, cost;
};
struct B {
  int x, y;
};
B a[100000];
bool operator<(A a, A b) { return a.cost < b.cost; }
int pa[100000];
vector<A> u;
int root(int x) {
  if (pa[x] == x) return x;
  return pa[x] = root(pa[x]);
}
signed main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].x >> a[i].y;
    pa[i] = i;
  }
  int sum = 0, ans = n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      u.push_back(A{i, j, (abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y))});
  }
  sort(u.begin(), u.end());
  int i = 0;
  while (ans > 1) {
    if (root(u[i].from) != root(u[i].to)) {
      pa[u[i].from] = pa[u[i].to];
      ans--;
      sum += u[i].cost;
    }
    i++;
  }
  cout << sum << endl;
  getchar();
  getchar();
}
