#include <bits/stdc++.h>
using namespace std;
long long l[300005], r[300005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  multiset<long long> lset, rset;
  long long i;
  for (i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    lset.insert(l[i]);
    rset.insert(r[i]);
  }
  long long ans = 0;
  for (i = 0; i < n; i++) {
    lset.erase(lset.find(l[i]));
    rset.erase(rset.find(r[i]));
    long long maxl, minr;
    auto itl = lset.end();
    itl--;
    auto itr = rset.begin();
    maxl = (*itl);
    minr = (*itr);
    ans = max(ans, max(0ll, minr - maxl));
    lset.insert(l[i]);
    rset.insert(r[i]);
  }
  cout << ans << '\n';
  return 0;
}
