#include <bits/stdc++.h>
using namespace std;
const int mx = 3 * 100 * 1002;
pair<int, int> arr[mx];
int n;
int func(int idx) {
  int lo, hi, i, j;
  lo = -1;
  hi = (int)1e9 + 5;
  for (i = 0; i < n; i++) {
    if (i == idx) continue;
    lo = max(lo, arr[i].first);
    hi = min(hi, arr[i].second);
  }
  return max(0, hi - lo);
}
int main() {
  int i, a, b, l, r, mn = (int)1e9 + 5, mx = -1;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &l, &r);
    arr[i] = make_pair(l, r);
    if (l > mx) {
      mx = l;
      a = i;
    }
    if (r < mn) {
      mn = r;
      b = i;
    }
  }
  printf("%d\n", max(func(a), func(b)));
  return 0;
}
