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