#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n;
struct intt {
  int L, R;
};
intt inst[300002];
intt v[300002];
intt v2[300002];
intt intersect(intt a, intt b) {
  if (a.L == -1) return {-1, -1};
  if (a.R < b.L || a.L > b.R) return {-1, -1};
  return {max(a.L, b.L), min(a.R, b.R)};
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> inst[i].L >> inst[i].R;
  for (int i = 1; i <= n; ++i)
    if (i == 1)
      v[i] = inst[i];
    else
      v[i] = intersect(v[i - 1], inst[i]);
  for (int i = n; i >= 1; --i)
    if (i == n)
      v2[i] = inst[i];
    else
      v2[i] = intersect(v2[i + 1], inst[i]);
  int Lmax = 0;
  for (int i = 1; i <= n; ++i) {
    intt p;
    if (i == 1)
      p = v2[i + 1];
    else if (i == n)
      p = v[i - 1];
    else
      p = intersect(v[i - 1], v2[i + 1]);
    if (p.L == -1) continue;
    Lmax = max(Lmax, p.R - p.L);
  }
  cout << Lmax;
  return 0;
}
