#include <bits/stdc++.h>
using namespace std;
int getLength(pair<int, int> a, pair<int, int> b) {
  return (
      (a.first - b.first < 0 ? -(a.first - b.first) : a.first - b.first) >
              (a.second - b.second < 0 ? -(a.second - b.second)
                                       : a.second - b.second)
          ? (a.second - b.second < 0 ? -(a.second - b.second)
                                     : a.second - b.second)
          : (a.first - b.first < 0 ? -(a.first - b.first) : a.first - b.first));
}
int main() {
  int N;
  long long int total = 0;
  cin >> N;
  vector<pair<int, int>> town;
  bool used[N];
  for (int i = 0; i < N; i++) {
    used[i] = false;
    int x, y;
    cin >> x >> y;
    town.push_back(make_pair(x, y));
  }
  vector<pair<int, int>> po;
  int size = 0;
  po.push_back(town[0]);
  town.erase(town.begin());
  size = po.size();
  while (size < N) {
    int mini = 100000000;
    pair<int, int> num;
    int town_size = town.size();
    for (int i = 0; i < size; i++) {
      for (int j = 0; j < town_size; j++) {
        int q = getLength(po[i], town[j]);
        if (mini > q) {
          mini = q;
          num = make_pair(i, j);
        }
      }
    }
    po.push_back(town[num.second]);
    total += getLength(town[num.second], po[num.first]);
    town.erase(town.begin() + num.second);
    size = po.size();
  }
  cout << total << endl;
}
