#include <bits/stdc++.h>
using namespace std;
int l[300005], r[300005];
int main() {
  int n;
  scanf("%d", &n);
  int lm = -1, rm = 0x3f3f3f3f;
  int ansl = 0, ansr = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &l[i], &r[i]);
    if (l[i] > lm) {
      ansl = i;
      lm = l[i];
    }
    if (r[i] < rm) {
      ansr = i;
      rm = r[i];
    }
  }
  int lmm = 0x3f3f3f3f, rmm = -1;
  for (int i = 1; i <= n; i++) {
    if (l[i] == lm && lmm > r[i]) {
      lmm = r[i];
      ansl = i;
    }
    if (r[i] == rm && rmm < l[i]) {
      rmm = l[i];
      ansr = i;
    }
  }
  if (ansl == ansr) {
    int lll = -1, rrr = 0x3f3f3f3f;
    for (int i = 1; i <= n; i++) {
      if (i == ansl) continue;
      lll = max(lll, l[i]);
      rrr = min(rrr, r[i]);
    }
    if (rrr <= lll) {
      printf("0\n");
    } else
      printf("%d\n", rrr - lll);
  } else {
    int ll1 = -1, rr1 = 0x3f3f3f3f;
    for (int i = 1; i <= n; i++) {
      if (i == ansl) continue;
      ll1 = max(ll1, l[i]);
      rr1 = min(rr1, r[i]);
    }
    int ll2 = -1, rr2 = 0x3f3f3f3f;
    for (int i = 1; i <= n; i++) {
      if (i == ansr) continue;
      ll2 = max(ll2, l[i]);
      rr2 = min(rr2, r[i]);
    }
    if (ll2 >= rr2 && ll1 >= rr1)
      printf("0\n");
    else {
      int ans = max(rr2 - ll2, rr1 - ll1);
      printf("%d\n", ans);
    }
  }
  return 0;
}
