#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200105], new_adj[200105];
int xMove[] = {0, 1, 0, -1, 1, 1, -1, -1, 2, 2, -2, -2, 1, 1, -1, -1};
int yMove[] = {1, 0, -1, 0, 1, -1, 1, -1, 1, -1, 1, -1, 2, -2, 2, -2};
void clr(int n) {
  for (int i = 0; i < n + 2; i++) adj[i].clear();
}
int main() {
  cin.tie(0), cout.tie(0);
  ios_base::sync_with_stdio(0);
  int TC = 1;
  int n, q, m, e, t;
  {
    cin >> n;
    vector<array<int, 2>> segs(n);
    for (auto &[l, r] : segs) cin >> l >> r;
    int pl[n + 2], sl[n + 2], pr[n + 2], sr[n + 2];
    pl[0] = pl[n + 1] = sl[0] = sl[n + 1] = 0;
    pr[0] = pr[n + 1] = sr[0] = sr[n + 1] = 1e9;
    for (int i = 1; i <= n; i++) {
      pl[i] = max(segs[i - 1][0], pl[i - 1]);
      pr[i] = min(segs[i - 1][1], pr[i - 1]);
    }
    for (int i = n; i >= 1; i--) {
      sl[i] = max(segs[i - 1][0], sl[i + 1]);
      sr[i] = min(segs[i - 1][1], sr[i + 1]);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      int lmx = max(pl[i - 1], sl[i + 1]);
      int rmn = min(pr[i - 1], sr[i + 1]);
      if (lmx <= rmn and ans < rmn - lmx) ans = rmn - lmx;
    }
    cout << ans << endl;
  }
  return 0;
}
