#include <bits/stdc++.h>
using namespace std;
multiset<int, greater<int> > L;
multiset<int> R;
int l[300005], r[300005];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> l[i] >> r[i];
    L.insert(l[i]);
    R.insert(r[i]);
  }
  int sol = 0;
  for (int i = 0; i < n; ++i) {
    L.erase(L.find(l[i]));
    R.erase(R.find(r[i]));
    sol = max(sol, *R.begin() - *L.begin());
    L.insert(l[i]);
    R.insert(r[i]);
  }
  cout << sol;
  return 0;
}
