#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i;
  int ans = 0;
  cin >> n;
  long long l[300001], r[300001];
  multiset<int> a, b;
  for (i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    a.insert(l[i]);
    b.insert(r[i]);
  }
  for (i = 0; i < n; i++) {
    a.erase(a.find(l[i]));
    b.erase(b.find(r[i]));
    ans = max(ans, *b.begin() - *a.rbegin());
    a.insert(l[i]);
    b.insert(r[i]);
  }
  cout << ans;
  return 0;
}
