#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > cities, cities2;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    cities.push_back(make_pair(x, y));
    cities2.push_back(make_pair(y, x));
  }
  sort(cities.begin(), cities.end());
  sort(cities2.begin(), cities2.end());
  int ans1 = 0, ans2 = 0;
  for (int i = 0; i < cities.size() - 1; ++i) {
    ans1 += min(abs(cities[i].first - cities[i + 1].first),
                abs(cities[i].second - cities[i + 1].second));
    ans2 += min(abs(cities2[i].first - cities2[i + 1].first),
                abs(cities2[i].second - cities2[i + 1].second));
  }
  cout << min(ans1, ans2);
}
