#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0, a = 0, b = 0, i = 0, idx = 0, idy = 0;
  long double d = 0;
  vector<pair<int, int> > vp;
  vector<pair<long double, int> > dist;
  vector<int> x, y;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &a, &b);
    vp.push_back(make_pair(a, b));
    x.push_back(a);
    y.push_back(b);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  long long int res = 0;
  for (i = 0; i < n - 1; i++) {
    idx = lower_bound(x.begin(), x.end(), vp[i].first) - x.begin();
    idy = lower_bound(y.begin(), y.end(), vp[i].second) - y.begin();
    a = INT_MAX;
    if (idx - 1 >= 0) a = min(abs(vp[i].first - x[idx - 1]), a);
    if (idx + 1 < n) a = min(abs(vp[i].first - x[idx + 1]), a);
    if (idy - 1 >= 0) a = min(abs(vp[i].second - y[idy - 1]), a);
    if (idy + 1 < n) a = min(abs(vp[i].second - y[idy + 1]), a);
    res += a;
  }
  printf("%lld\n", res);
  return 0;
}
