#include <bits/stdc++.h>
using namespace std;
long long int l[1000000], r[1000000], pl[1000000], pr[1000000], sl[1000000],
    sr[1000000];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(pl, -1, sizeof(pl));
  memset(pr, 1000000003, sizeof(pr));
  memset(sl, -1, sizeof(sl));
  memset(sr, 1000000003, sizeof(sr));
  long long int a, b, c;
  cin >> a;
  for (long long int i = 1; i <= a; i++) {
    cin >> l[i];
    cin >> r[i];
  }
  for (long long int i = 1; i <= a; i++) {
    pl[i] = max(pl[i - 1], l[i]);
    pr[i] = min(pr[i - 1], r[i]);
  }
  for (int i = a; i >= 1; i--) {
    sl[i] = max(sl[i + 1], l[i]);
    sr[i] = min(sr[i + 1], r[i]);
  }
  long long int an = 0;
  for (long long int i = 1; i <= a; i++) {
    long long int lb = max(pl[i - 1], sl[i + 1]),
                  rb = min(pr[i - 1], sr[i + 1]);
    an = max(an, rb - lb);
  }
  cout << an << endl;
  return 0;
}
