#include <bits/stdc++.h>
using namespace std;
struct node {
  long long li, ri;
} sum[400000];
long long pmx[400000], nmx[400000];
long long pmi[400000], nmi[400000];
int main() {
  long long n;
  memset(pmi, 0x7f7f7f7f, sizeof(pmi));
  memset(nmi, 0x7f7f7f7f, sizeof(nmi));
  memset(pmx, -0x7f7f7f7f, sizeof(pmx));
  memset(nmx, -0x7f7f7f7f, sizeof(nmx));
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld %lld", &sum[i].li, &sum[i].ri);
  }
  for (long long i = 1; i <= n; i++) {
    pmx[i] = max(sum[i].li, pmx[i - 1]);
    pmi[i] = min(sum[i].ri, pmi[i - 1]);
  }
  for (long long i = n; i >= 1; i--) {
    nmx[i] = max(sum[i].li, nmx[i + 1]);
    nmi[i] = min(sum[i].ri, nmi[i + 1]);
  }
  long long ans = -0x7f7f7f7f, sum1 = 0, sum2 = 0;
  for (long long i = 1; i <= n; i++) {
    sum1 = max(pmx[i - 1], nmx[i + 1]);
    sum2 = min(pmi[i - 1], nmi[i + 1]);
    ans = max(ans, sum2 - sum1);
  }
  if (ans < 0) {
    printf("0\n");
  } else
    printf("%lld\n", ans);
  return 0;
}
