#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, c = getchar(), f = 0;
  for (; c > '9' || c < '0'; f = c == '-', c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0';
  return f ? -x : x;
}
const int maxn = 3e5 + 10;
int a[maxn], b[maxn];
int main() {
  int n = read();
  int l = 0, r = 0;
  a[0] = -1, b[0] = 0x3f3f3f3f;
  for (int i = 1; i <= n; i++) {
    a[i] = read(), b[i] = read();
    if (a[i] > a[l])
      l = i;
    else if (a[i] == a[l] && b[i] < b[l])
      l = i;
    if (b[i] < b[r])
      r = i;
    else if (b[i] == b[r] && a[i] > a[r])
      r = i;
  }
  int ans = 0;
  int ll = -1, rr = 0x3f3f3f3f;
  for (int i = 1; i <= n; i++) {
    if (i == l) continue;
    ll = max(ll, a[i]);
    rr = min(rr, b[i]);
  }
  ans = max(ans, rr - ll);
  ll = -1, rr = 0x3f3f3f3f;
  for (int i = 1; i <= n; i++) {
    if (i == r) continue;
    ll = max(ll, a[i]);
    rr = min(rr, b[i]);
  }
  ans = max(ans, rr - ll);
  cout << ans << endl;
  return 0;
}
