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