#include <bits/stdc++.h>
using namespace std;
int n, lmax = -1, lmaxr, rmin = 1e9, rminl, lmaxx, rminn, len;
int main() {
  int i, l, r, fl = 0, fr = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &l, &r);
    if (l > lmax) {
      lmaxx = lmax;
      lmax = l;
      lmaxr = r;
      fl = 1;
    } else if (l == lmax)
      fl = 0;
    else
      lmaxx = max(lmaxx, l);
    if (r < rmin) {
      rminn = rmin;
      rmin = r;
      rminl = l;
      fr = 1;
    } else if (r == rmin)
      fr = 0;
    else
      rminn = min(rminn, r);
  }
  len = rmin - lmax;
  if (fl == 1) {
    if (lmaxr == rmin && fr == 1)
      len = max(len, rminn - lmaxx);
    else
      len = max(rmin - lmaxx, len);
  }
  if (fr == 1) {
    if (rminl == lmax && fl == 1)
      len = max(len, rminn - lmaxx);
    else
      len = max(rminn - lmax, len);
  }
  if (len < 0)
    printf("0");
  else
    printf("%d", len);
}
