#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> left, right;
  multiset<int, greater<int>> stLeft;
  multiset<int> stRight;
  int n, x, y, maxIntersection = 0;
  cin >> n;
  for (int i = 0; i < int(n); i++) {
    cin >> x >> y;
    left.push_back(x);
    right.push_back(y);
    stLeft.insert(x);
    stRight.insert(y);
  }
  auto itL = left.begin(), itR = right.begin();
  for (int i = 0; i < int(n); i++) {
    auto itSR = stRight.find(*itR);
    auto itSL = stLeft.find(*itL);
    int l = *itSL, r = *itSR;
    stRight.erase(itSR);
    stLeft.erase(itSL);
    maxIntersection =
        max(maxIntersection, (*stRight.begin()) - (*stLeft.begin()));
    stRight.insert(r);
    stLeft.insert(l);
    itL++;
    itR++;
  }
  cout << maxIntersection << '\n';
  return 0;
}
