#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int n, ml = -1, mr = 0x3f3f3f3f, l1 = -1, r1 = 0x3f3f3f3f, a[maxn], b[maxn],
       c[maxn], d[maxn];
int main() {
  scanf("%d", &n);
  int flag = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    if (a[i] > ml) {
      l1 = ml;
      ml = a[i];
    } else if (a[i] > l1)
      l1 = a[i];
    if (b[i] < mr) {
      r1 = mr;
      mr = b[i];
    } else if (b[i] < r1)
      r1 = b[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int l = ml, r = mr;
    if (a[i] == ml) l = l1;
    if (b[i] == mr) r = r1;
    int len = max(0, r - l);
    ans = max(len, ans);
  }
  printf("%d", ans);
  return 0;
}
