#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > v;
bool comp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v.push_back(make_pair(x, y));
  }
  sort(v.begin(), v.end());
  vector<pair<int, int> >::iterator it = v.begin();
  pair<int, int> prev = *it;
  it = upper_bound(v.begin(), v.end(), prev, comp);
  long long cost = 0;
  while (it != v.end()) {
    cost += min(abs(it->first - prev.first), abs(it->second - prev.second));
    prev = *it;
    it = upper_bound(v.begin(), v.end(), prev, comp);
  }
  cout << cost << endl;
  return 0;
}
