#include <bits/stdc++.h>
using namespace std;
int n, k;
pair<int, int> s[300005];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i].second >> s[i].first;
  }
  sort(s, s + n);
  int res1 = s[1].first - s[1].second, res2 = s[1].first - s[1].second;
  int mini = s[0].first - s[0].second, mini2 = s[0].first - s[0].second, vt = 0;
  for (int i = 1; i < n; i++) {
    if (mini > s[0].first - s[i].second) {
      mini = s[0].first - s[i].second;
      vt = i;
    }
  }
  for (int i = 1; i < n; i++) {
    if (mini2 > s[0].first - s[i].second && vt != i) {
      mini2 = s[0].first - s[i].second;
    }
  }
  res1 = mini2;
  for (int i = 1; i < n; i++) {
    if (res2 > s[1].first - s[i].second) {
      res2 = s[1].first - s[i].second;
    }
  }
  if (max(res2, res1) <= 0)
    cout << 0;
  else
    cout << max(res2, res1);
}
