#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, max = 0;
  cin >> n;
  vector<int> L(n), R(n), L1(n), R1(n);
  for (int i = 0; i < n; i++) {
    cin >> L[i] >> R[i];
    L1[i] = L[i];
    R1[i] = R[i];
  }
  sort(L.begin(), L.end());
  sort(R.begin(), R.end());
  for (int z = 0; z < n; z++) {
    int r = 0, l = n - 1;
    while (R[r] == R1[z] && R[r + 1] != R1[z]) r++;
    while (L[l] == L1[z] && L[l - 1] != L1[z]) l--;
    if (max < R[r] - L[l]) max = R[r] - L[l];
  }
  cout << max;
}
