#include <bits/stdc++.h>
using namespace std;
int i, j, cnt = 0;
pair<int, int> ipr[300050], pre[300050], suf[300050];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, l, r, ans = 0;
  cin >> n;
  for (i = 1; i < n + 1; i++) {
    cin >> ipr[i].first >> ipr[i].second;
  }
  pre[0].first = suf[n + 1].first = 0;
  pre[0].second = suf[n + 1].second = 1e9;
  for (i = 1; i < n + 1; i++) {
    pre[i].first = max(ipr[i].first, pre[i - 1].first);
    pre[i].second = min(ipr[i].second, pre[i - 1].second);
  }
  for (i = n + 1 - 1; i >= 1; i--) {
    suf[i].first = max(ipr[i].first, suf[i + 1].first);
    suf[i].second = min(ipr[i].second, suf[i + 1].second);
  }
  for (i = 1; i < n + 1; i++) {
    ans = max({0,
               min(pre[i - 1].second, suf[i + 1].second) -
                   max(pre[i - 1].first, suf[i + 1].first),
               ans});
  }
  cout << ans << endl;
  return ~~(0 ^ 0 ^ 0);
}
