#include <bits/stdc++.h>
using namespace std;
pair<int, int> sgms[300010];
int s[300010];
int e[300010];
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &s[i], &e[i]);
    sgms[i].first = s[i];
    sgms[i].second = e[i];
  }
  sort(s, s + n);
  sort(e, e + n);
  int mxs = s[n - 1];
  int mxs2 = s[n - 2];
  int mie = e[0];
  int mie2 = e[1];
  int ans = max(0, mie - mxs);
  for (int i = 0; i < n; i++) {
    int ts = mxs;
    int te = mie;
    if (ts == sgms[i].first) ts = mxs2;
    if (te == sgms[i].second) te = mie2;
    ans = max(ans, te - ts);
  }
  cout << ans;
  return 0;
}
