#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int n, i, j;
pair<int, int> a[100005];
int main() {
  scanf("%d", &n);
  vector<int> x, y;
  for (i = 0; i < n; i++) {
    scanf("%d%d", &a[i].first, &a[i].second);
    x.push_back(a[i].first);
    y.push_back(a[i].second);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  long long res = 0;
  for (i = 0; i < n - 1; i++) {
    int id = lower_bound(x.begin(), x.end(), a[i].first) - x.begin();
    int id1 = lower_bound(y.begin(), y.end(), a[i].second) - y.begin();
    int minval = INF;
    if (id - 1 >= 0) minval = min(minval, x[id] - x[id - 1]);
    if (id + 1 < x.size()) minval = min(minval, x[id + 1] - x[id]);
    if (id1 - 1 >= 0) minval = min(minval, y[id1] - y[id1 - 1]);
    if (id1 + 1 < y.size()) minval = min(minval, y[id1 + 1] - y[id1]);
    res += minval;
  }
  printf("%lld\n", res);
}
