#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, x[N], y[N];
struct Edge {
  int u, v, w;
  Edge() {}
  Edge(int u, int v, int w) : u(u), v(v), w(w) {}
  bool operator<(const Edge &rhs) const { return w < rhs.w; }
};
vector<Edge> v;
int fa[N];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", x + i, y + i);
  long long res = 0;
  for (int i = 1; i < n; i++)
    res += min(abs(x[i] - x[i - 1]), abs(y[i] - y[i - 1]));
  printf("%d\n", res);
  return 0;
}
