#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
int i, j, n, ans = 0, prel[maxn], prer[maxn], sufl[maxn], sufr[maxn], l[maxn],
             r[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (i = 1; i <= n; i++) cin >> l[i] >> r[i];
  prel[0] = 0;
  prer[0] = INF;
  sufl[0] = 0;
  sufr[0] = INF;
  prel[n + 1] = 0;
  prer[n + 1] = INF;
  sufl[n + 1] = 0;
  sufr[n + 1] = INF;
  for (i = 1; i <= n; i++) {
    prel[i] = max(l[i], prel[i - 1]);
    prer[i] = min(r[i], prer[i - 1]);
  }
  for (i = n - 1; i >= 0; i--) {
    sufl[n - i] = max(l[i + 1], sufl[n - i - 1]);
    sufr[n - i] = min(r[i + 1], sufr[n - i - 1]);
  }
  for (i = 1; i <= n; i++) {
    ans =
        max(ans, min(prer[i - 1], sufr[n - i]) - max(prel[i - 1], sufl[n - i]));
  }
  cout << ans << endl;
  return 0;
}
