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