#include <bits/stdc++.h>
using namespace std;
pair<int, int> l[300010];
pair<int, int> r[300010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (int)(0); i < (int)(n); ++i) {
    scanf("%d%d", &l[i].first, &r[i].first);
    l[i].second = r[i].second = i;
  }
  int res = 0;
  sort(l, l + n, greater<pair<int, int> >());
  sort(r, r + n);
  for (int i = (int)(0); i < (int)(n); ++i) {
    int maxl = l[0].second == i ? l[1].first : l[0].first;
    int minr = r[0].second == i ? r[1].first : r[0].first;
    res = max(res, minr - maxl);
  }
  printf("%d\n", res);
  return 0;
}
