#include <bits/stdc++.h>
int read() {
  int k = 0;
  char tmp = getchar();
  while ('0' > tmp || '9' < tmp) tmp = getchar();
  while ('0' <= tmp && '9' >= tmp) {
    k = 10 * k + tmp - '0';
    tmp = getchar();
  }
  return k;
}
int n, a[300005], b[300005], get1 = -1, get2 = -1, l, r, ans;
int main() {
  n = read();
  a[0] = read();
  b[0] = read();
  l = a[0];
  r = b[0];
  for (int i = 1; i < n; ++i) {
    a[i] = read();
    b[i] = read();
    l = std::max(l, a[i]);
    r = std::min(r, b[i]);
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] == l)
      if (get1 == -1)
        get1 = i;
      else
        get1 = -2;
    if (b[i] == r)
      if (get2 == -1)
        get2 = i;
      else
        get2 = -2;
  }
  if (get1 >= 0) {
    l = -1;
    r = 1000000005;
    for (int i = 0; i < n; ++i)
      if (i != get1) {
        l = std::max(l, a[i]);
        r = std::min(r, b[i]);
      }
  }
  ans = std::max(ans, r - l);
  if (get2 >= 0) {
    l = -1;
    r = 1000000005;
    for (int i = 0; i < n; ++i)
      if (i != get2) {
        l = std::max(l, a[i]);
        r = std::min(r, b[i]);
      }
  }
  ans = std::max(ans, r - l);
  printf("%d", ans);
  return 0;
}
