#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  int n;
  cin >> n;
  set<pair<int, int> > l, r;
  vector<int> le(n), ri(n);
  for (int i = 0; i < n; i++) {
    cin >> le[i] >> ri[i];
    l.insert({le[i], i});
    r.insert({ri[i], i});
  }
  int sol = 0;
  for (int i = 0; i < n; i++) {
    l.erase({le[i], i});
    r.erase({ri[i], i});
    int left = l.rbegin()->first;
    int right = r.begin()->first;
    if (right >= left) sol = max(sol, right - left);
    l.insert({le[i], i});
    r.insert({ri[i], i});
  }
  cout << sol << endl;
  return 0;
}
