#include <bits/stdc++.h>
using namespace std;
const int MAX_E = 100 * 99 / 2;
struct edge {
  int u, v, cost;
};
edge es[MAX_E];
int V, E;
vector<int> par;
vector<int> rnk;
void init_union_find(int n) {
  par = vector<int>(n);
  rnk = vector<int>(n);
  for (int i = 0; i < n; i++) {
    par[i] = i;
    rnk[i] = 0;
  }
}
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (rnk[x] < rnk[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rnk[x] == rnk[y]) rnk[x]++;
  }
}
bool same(int x, int y) { return find(x) == find(y); }
bool comp(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
int kruskal() {
  sort(es, es + E, comp);
  init_union_find(V);
  int res = 0;
  for (int i = 0; i < E; i++) {
    edge e = es[i];
    if (!same(e.u, e.v)) {
      unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}
int main() {
  while (cin >> V) {
    E = V * (V - 1) / 2;
    int c;
    int k = 0;
    int x[V], y[V];
    for (int i = 0; i < V; i++) {
      cin >> x[i] >> y[i];
    }
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < i; j++) {
        c = min(abs(x[i] - x[j]), abs(y[i] - y[j]));
        edge e = {i, j, c};
        es[k++] = e;
      }
    }
    int res = kruskal();
    cout << res << endl;
  }
  return 0;
}
