#include <bits/stdc++.h>
using namespace std;
struct town {
  int x, y;
};
int n, ans;
town a[100010];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i].x >> a[i].y;
  for (int i = 0; i < n - 1; i++) {
    vector<int> d;
    for (int j = 0; j < n; j++)
      if (i != j) d.push_back(min(abs(a[i].x - a[j].x), abs(a[i].y - a[j].y)));
    sort(d.begin(), d.end());
    ans += d[0];
  }
  cout << ans;
  return 0;
}
