#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int INF = 1e9 + 5;
int n;
struct point {
  int x;
  int y;
  int ind;
} p[N];
int cost[N];
long long ans;
int abs(int x) {
  if (x < 0) return -x;
  return x;
}
bool point_sortx(point a, point b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}
bool point_sorty(point a, point b) {
  if (a.y != b.y) return a.y < b.y;
  return a.x < b.x;
}
int main() {
  int i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &p[i].x, &p[i].y);
    p[i].ind = i;
    cost[i] = INF;
  }
  sort(p + 1, p + n + 1, point_sortx);
  cost[p[1].ind] = min(cost[p[1].ind], p[2].x - p[1].x);
  for (i = 1; i < n; i++)
    cost[p[i].ind] =
        min(cost[p[i].ind], min(p[i].x - p[i - 1].x, p[i + 1].x - p[i].x));
  cost[p[n].ind] = min(cost[p[n].ind], p[n].x - p[n - 1].x);
  sort(p + 1, p + n + 1, point_sorty);
  cost[p[1].ind] = min(cost[p[1].ind], p[2].y - p[1].y);
  for (i = 1; i < n; i++)
    cost[p[i].ind] =
        min(cost[p[i].ind], min(p[i].y - p[i - 1].y, p[i + 1].y - p[i].y));
  cost[p[n].ind] = min(cost[p[n].ind], p[n].y - p[n - 1].y);
  for (i = 1; i <= n; i++) {
    ans += cost[i];
  }
  cout << ans << endl;
  return 0;
}
