#include <bits/stdc++.h>
using namespace std;
struct Edge {
  long long int to;
  long long int cost;
};
struct Node {
  long long int pos;
  long long int cost;
  bool operator<(const Node& r) const { return cost > r.cost; }
};
vector<long long int> dijkstra(vector<Edge>* g, long long int n) {
  long long int INF = pow(10, 10);
  priority_queue<Node> que;
  que.push({0, 0});
  vector<long long int> res(n, INF);
  while (que.size()) {
    Node n = que.top();
    que.pop();
    if (res[n.pos] == INF)
      res[n.pos] = n.cost;
    else
      continue;
    for (auto e : g[n.pos]) {
      que.push({e.to, e.cost});
    }
  }
  return res;
}
int main() {
  long long int n;
  cin >> n;
  vector<long long int> x(n);
  vector<long long int> y(n);
  for (long long int i = 0; i < (n); i++) cin >> x[i] >> y[i];
  vector<Edge> g[n];
  for (long long int src = 0; src < (n); src++) {
    for (long long int sink = 0; sink < (n); sink++) {
      if (src == sink) continue;
      long long int xCost = abs(x[src] - x[sink]);
      long long int yCost = abs(y[src] - y[sink]);
      g[src].push_back({sink, min(xCost, yCost)});
    }
  }
  vector<long long int> res = dijkstra(g, n);
  long long int sum = 0;
  for (auto e : res) sum += e;
  cout << sum << endl;
  return 0;
}
