#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, l, r, mx = 0;
  cin >> n;
  vector<pair<int, int> > a, b;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    a.emplace_back(l, i);
    b.emplace_back(r, i);
  }
  sort(a.begin(), a.end(), greater<pair<int, int> >());
  sort(b.begin(), b.end());
  if (a[0].second == b[0].second)
    mx = max(0, b[1].first - a[1].first);
  else {
    mx = max(mx, b[1].first - a[0].first);
    mx = max(mx, b[0].first - a[1].first);
  }
  cout << mx << endl;
  return 0;
}
