#include <bits/stdc++.h>
using namespace std;
multiset<int> l, r;
int main() {
  int n;
  cin >> n;
  vector<long long> left, right;
  for (int y = 0; y < n; y++) {
    int a, b;
    cin >> a >> b;
    left.push_back(a);
    right.push_back(b);
    l.insert(left[y]);
    r.insert(right[y]);
  }
  int ans = 0;
  for (int y = 0; y < n; y++) {
    l.erase(l.find(left[y]));
    r.erase(r.find(right[y]));
    ans = max(ans, *r.begin() - *l.rbegin());
    l.insert(left[y]);
    r.insert(right[y]);
  }
  cout << ans << "\n";
  return 0;
}
