#include <bits/stdc++.h>
int main(void) {
  int n;
  int *x, *y, *cost;
  int **data;
  bool *flg;
  scanf("%d", &n);
  x = (int *)malloc(n * sizeof(int));
  y = (int *)malloc(n * sizeof(int));
  cost = (int *)malloc(n * sizeof(int));
  flg = (bool *)malloc(n * sizeof(bool));
  data = (int **)malloc(n * sizeof(int *));
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &x[i], &y[i]);
    data[i] = (int *)malloc(n * sizeof(int));
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      data[i][j] = ((x[i] - x[j]) > 0 ? (x[i] - x[j]) : -(x[i] - x[j])) >
                           ((y[i] - y[j]) > 0 ? (y[i] - y[j]) : -(y[i] - y[j]))
                       ? ((y[i] - y[j]) > 0 ? (y[i] - y[j]) : -(y[i] - y[j]))
                       : ((x[i] - x[j]) > 0 ? (x[i] - x[j]) : -(x[i] - x[j]));
      data[j][i] = data[i][j];
    }
  }
  long long int ans = 0;
  int now = 0, tmp, min, minp;
  for (int i = 0; i < n; i++) {
    cost[i] = -1;
    flg[i] = false;
  }
  flg[0] = true;
  while (1) {
    min = -1;
    minp = -1;
    for (int i = 0; i < n; i++) {
      if (flg[i]) {
        continue;
      }
      tmp = (cost[i] == -1                ? data[now][i]
             : (data[now][i]) > (cost[i]) ? (cost[i])
                                          : (data[now][i]));
      cost[i] = tmp;
      if (min == -1 || (min != -1 && min > tmp)) {
        min = tmp;
        minp = i;
      }
    }
    if (minp == -1) {
      break;
    }
    flg[minp] = true;
    ans += data[now][minp];
    now = minp;
  }
  printf("%lld\n", ans);
  return 0;
}
