#include <bits/stdc++.h>
using namespace std;
const int M = 300 * 1000 + 10;
int l[M], r[M];
int n;
int main() {
  ios::sync_with_stdio(false);
  int ml = 0, mr = 0;
  cin >> n >> l[0] >> r[0];
  for (int i = 1; i < n; ++i) {
    cin >> l[i] >> r[i];
    if (l[i] > l[ml]) ml = i;
    if (r[i] < r[mr]) mr = i;
  }
  sort(l, l + n);
  sort(r, r + n);
  int ans = 0;
  if (ml == mr && l[n - 2] < l[n - 1] && r[0] < r[1]) {
    ans = max(ans, r[1] - l[n - 2]);
  }
  ans = max(ans, r[0] - l[n - 2]);
  ans = max(ans, r[1] - l[n - 1]);
  cout << ans << endl;
  return 0;
}
