#include <bits/stdc++.h>
using namespace std;
long long maxd(long long a, long long b) {
  if (a >= b) {
    return a;
  }
  return b;
}
long long mind(long long a, long long b) {
  if (a <= b) {
    return a;
  }
  return b;
}
long long gcd(long long a, long long b) {
  if (a < b) {
    swap(a, b);
  }
  while (b) {
    long long r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
int isPrim(int a) {
  if (a == 1) {
    return 0;
  }
  for (int i = 2; i <= (a + 1) / 2; i++) {
    if (a % i == 0) {
      return 0;
    }
  }
  return 1;
}
long long mod_pow(long long x, long long n, long long mod) {
  long long ret = 1;
  while (n > 0) {
    if (n % 2 == 1) {
      ret = (ret * x) % mod;
    }
    x = (x * x) % mod;
    n = n / 2;
  }
  return ret;
}
struct XX {
  int x;
  int kx;
  int y;
  int ky;
  int i;
};
class xxIntx {
 public:
  bool operator()(const XX& riLeft, const XX& riRight) const {
    if ((riLeft.x) == (riRight.x)) {
      return riLeft.y < riRight.y;
    }
    return (riLeft.x) < (riRight.x);
  }
};
class xxInty {
 public:
  bool operator()(const XX& riLeft, const XX& riRight) const {
    if ((riLeft.y) == (riRight.y)) {
      return riLeft.x < riRight.x;
    }
    return (riLeft.y) < (riRight.y);
  }
};
class xxInti {
 public:
  bool operator()(const XX& riLeft, const XX& riRight) const {
    if ((riLeft.i) == (riRight.i)) {
      return riLeft.x < riRight.x;
    }
    return (riLeft.i) < (riRight.i);
  }
};
class xxGreater {
 public:
  bool operator()(const XX& riLeft, const XX& riRight) const {
    if ((riLeft.x) == (riRight.x)) {
      return riLeft.i > riRight.i;
    }
    return (riLeft.x) > (riRight.x);
  }
};
int main(int argc, const char* argv[]) {
  int N;
  cin >> N;
  XX a[100];
  for (int i = 0; i < N; i++) {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    a[i].x = tmp1;
    a[i].y = tmp2;
    a[i].i = i;
  }
  sort(a, a + N, xxIntx());
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      a[i].kx = a[i + 1].x - a[i].x;
    } else if (i == N - 1) {
      a[i].kx = a[i].x - a[i - 1].x;
    } else {
      a[i].kx = ((a[i].x - a[i - 1].x) < (a[i + 1].x - a[i].x)
                     ? (a[i].x - a[i - 1].x)
                     : (a[i + 1].x - a[i].x));
    }
  }
  sort(a, a + N, xxInty());
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      a[i].ky = a[i + 1].y - a[i].y;
    } else if (i == N - 1) {
      a[i].ky = a[i].y - a[i - 1].y;
    } else {
      a[i].ky = ((a[i].y - a[i - 1].y) < (a[i + 1].y - a[i].y)
                     ? (a[i].y - a[i - 1].y)
                     : (a[i + 1].y - a[i].y));
    }
  }
  long long ans = 0;
  for (int i = 0; i < N - 1; i++) {
    if (a[i].ky < a[i].kx) {
      ans += a[i].ky;
    } else {
      ans += a[i].kx;
    }
  }
  cout << ans << endl;
  return 0;
}
