#include <bits/stdc++.h>
void insert(long, long);
long eval_vert(int);
typedef struct vert {
  long x;
  long y;
  int num;
} vert;
vert verts[100000];
int vert_num = 0;
int main(void) {
  int N, i;
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%ld %ld", &(verts[vert_num].x), &(verts[vert_num].y));
    verts[vert_num].num = vert_num;
    vert_num++;
  }
  printf("%ld", eval_vert(N));
  return 0;
}
long eval_vert(int N) {
  int i, j;
  int root;
  long costs[100000] = {0};
  vert tmp;
  long cost_tmp;
  long total_cost;
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      if (verts[i].x < verts[j].x) {
        tmp = verts[i];
        verts[i] = verts[j];
        verts[j] = tmp;
      }
    }
  }
  for (i = 0; i < N; i++) {
    if (i > 0 && i < N - 1) {
      costs[verts[i].num] = labs(verts[i + 1].x - verts[i].x);
    } else if (i == 0) {
      costs[verts[i].num] = verts[i + 1].x - verts[i].x;
    } else if (i == N - 1) {
      costs[verts[i].num] = 0;
      root = verts[i].num;
    }
  }
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      if (verts[i].y < verts[j].y) {
        tmp = verts[i];
        verts[i] = verts[j];
        verts[j] = tmp;
      }
    }
  }
  for (i = 0; i < N; i++) {
    if (i > 0 && i < N - 1) {
      cost_tmp = labs(verts[i + 1].y - verts[i].y);
      if (cost_tmp < costs[verts[i].num]) costs[verts[i].num] = cost_tmp;
    } else if (i == 0) {
      cost_tmp = verts[i + 1].y - verts[i].y;
      if (cost_tmp < costs[verts[i].num]) costs[verts[i].num] = cost_tmp;
    } else if (i == N - 1) {
      cost_tmp = verts[i].y - verts[i - 1].y;
      if (cost_tmp < costs[verts[i].num]) costs[verts[i].num] = cost_tmp;
    }
  }
  for (i = 0; i < N; i++) {
    total_cost += costs[i];
  }
  return total_cost;
}
