#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[300005], b[300005], c[300005];
int n, res = 0;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
  int l = 0, r = 1000000001;
  b[0].first = 0;
  b[0].second = 1000000001;
  c[n].first = a[n].first;
  c[n].second = a[n].second;
  for (int i = 1; i < n; i++) {
    b[i].first = max(a[i].first, b[i - 1].first);
    b[i].second = min(a[i].second, b[i - 1].second);
  }
  res = max(0, b[n - 1].second - b[n - 1].first);
  for (int i = n - 1; i >= 1; i--) {
    l = max(l, a[i + 1].first);
    r = min(r, a[i + 1].second);
    res = max(res, min(b[i - 1].second, r) - max(b[i - 1].first, l));
  }
  cout << res;
  return 0;
}
