#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5 + 17;
const int MOD = 1e9 + 7;
long long d[MaxN];
int n;
set<int> S;
pair<int, int> a[MaxN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &a[i].first, &a[i].second);
    S.insert(a[i].second);
  }
  sort(a + 1, a + n + 1);
  for (int i = 2; i <= n; ++i) d[i] = d[i - 1] + (a[i].first - a[i - 1].first);
  for (int i = 1; i <= n; ++i) swap(a[i].first, a[i].second), a[i].second = i;
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= 1000; ++i) {
    for (int j = 1; j < n; ++j) {
      int x = a[j].second;
      int y = a[j + 1].second;
      int w = a[j + 1].first - a[j].first;
      d[y] = min(d[y], d[x] + w);
      d[x] = min(d[x], d[y] + w);
    }
  }
  long long Sum = 0;
  for (int i = 1; i <= n; ++i) Sum = max(d[i], Sum);
  printf("%lld", Sum);
  return 0;
}
