#include <bits/stdc++.h>
using namespace std;
int read() {
  int r = 0, f = 1;
  char p = getchar();
  while (p > '9' || p < '0') {
    if (p == '-') f = -1;
    p = getchar();
  }
  while (p >= '0' && p <= '9') {
    r = r * 10 + p - 48;
    p = getchar();
  }
  return r * f;
}
const int Maxn = 3e5 + 100;
const long long LINF = 1e18;
const int INF = 0x3f3f3f3f;
const int Mod = 10001;
struct Node {
  long long le, ri;
} a[Maxn], b[Maxn];
bool cmp1(const Node &a1, const Node &a2) { return a1.le < a2.le; }
bool cmp2(const Node &a1, const Node &a2) { return a1.ri < a2.ri; }
int main(void) {
  int n, x, y;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x >> y;
    a[i].le = b[i].le = x;
    a[i].ri = b[i].ri = y;
  }
  long long maxn = 0, le, ri;
  if (n == 2) {
    maxn = max(maxn, a[0].ri - a[0].le);
    maxn = max(maxn, a[1].ri - a[1].le);
    cout << maxn << endl;
    return 0;
  }
  sort(a, a + n, cmp1);
  sort(b, b + n, cmp2);
  if (a[n - 1].ri == b[0].ri)
    maxn = max(maxn, b[1].ri - a[n - 2].le);
  else {
    maxn = max(maxn, b[0].ri - a[n - 2].le);
    maxn = max(maxn, b[1].ri - a[n - 1].le);
  }
  cout << maxn << endl;
  return 0;
}
