#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long maxP = -1, maxS = -1;
  long minP = 1000000001, minS = 1000000001;
  long a, b;
  long T1[n];
  long T2[n];
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    T1[i] = a;
    T2[i] = b;
    if (a >= maxP) {
      maxS = maxP;
      maxP = a;
    } else {
      if (a > maxS) maxS = a;
    }
    if (b <= minP) {
      minS = minP;
      minP = b;
    } else {
      if (b < minS) minS = b;
    }
  }
  long top = minP - maxP;
  if (top < 0) top = 0;
  for (int i = 0; i < n; i++) {
    long maxi, mini;
    if (T1[i] == maxP)
      maxi = maxS;
    else
      maxi = maxP;
    if (T2[i] == minP)
      mini = minS;
    else
      mini = minP;
    if (mini - maxi > top) top = mini - maxi;
  }
  cout << top;
  return 0;
}
