#include <bits/stdc++.h>
using namespace std;
int l[300100], r[300100], prr[300100], prl[300100], sul[300100], sur[300100], n;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d %d", &l[i], &r[i]);
  prl[0] = sul[n] = 0;
  prr[0] = sur[n] = 1073741824;
  for (int i = 0; i < n; ++i) {
    prl[i + 1] = max(prl[i], l[i]);
    prr[i + 1] = min(prr[i], r[i]);
  }
  for (int i = n - 1; i >= 0; --i) {
    sul[i] = max(sul[i + 1], l[i]);
    sur[i] = min(sur[i + 1], r[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = max(ans, min(prr[i], sur[i + 1]) - max(prl[i], sul[i + 1]));
  }
  cout << ans << endl;
  return 0;
}
