#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> Left;
vector<int> Right;
map<pair<int, int>, int> excep;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie();
  cin >> n;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    Left.push_back(l);
    Right.push_back(r);
    excep[{l, r}] = 1;
  }
  sort(Left.begin(), Left.end(), greater<int>());
  sort(Right.begin(), Right.end());
  if (excep[{Left[0], Right[0]}] == 1)
    cout << max(0, Right[1] - Left[1]);
  else
    cout << max(0, max(Right[0] - Left[1], Right[1] - Left[0]));
}
