#include <bits/stdc++.h>
using namespace std;
void solve() {
  multiset<int> rs;
  multiset<int, greater<int> > ls;
  int n;
  cin >> n;
  vector<pair<int, int> > vek;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    vek.push_back(make_pair(x, y));
    rs.insert(y);
    ls.insert(x);
  }
  int ans = 0;
  for (auto it : vek) {
    ls.erase(ls.find(it.first));
    rs.erase(rs.find(it.second));
    ans = max(ans, *rs.begin() - *ls.begin());
    ls.insert(it.first);
    rs.insert(it.second);
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
