#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v, frontv, backv;
int main() {
  int n, i, x, y, j, mx;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    v.push_back(make_pair(x, y));
  }
  sort(v.begin(), v.end());
  frontv.push_back(make_pair(0, 1000000009));
  for (i = 0; i < n; i++) {
    x = max(frontv[i].first, v[i].first);
    y = min(frontv[i].second, v[i].second);
    frontv.push_back(make_pair(x, y));
  }
  frontv.push_back(make_pair(0, 1000000009));
  backv.push_back(make_pair(0, 1000000009));
  for (i = 0, j = n - 1; i < n && j >= 0; i++, j--) {
    x = max(backv[i].first, v[j].first);
    y = min(backv[i].second, v[j].second);
    backv.push_back(make_pair(x, y));
  }
  backv.push_back(make_pair(0, 1000000009));
  reverse(backv.begin(), backv.end());
  mx = -1;
  for (i = 1; i <= n; i++) {
    x = max(frontv[i - 1].first, backv[i + 1].first);
    y = min(frontv[i - 1].second, backv[i + 1].second);
    mx = max(mx, y - x);
  }
  if (mx > 0)
    cout << mx << endl;
  else
    cout << 0 << endl;
  return 0;
}
