#include <bits/stdc++.h>
using namespace std;
const int maxN = 300500;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int min_r = 1000000001;
  int cnt_min_r = 0;
  int sec_min_r = 0;
  int id_min_r = 0;
  int max_l = 0;
  int cnt_max_l = 0;
  int sec_max_l = 0;
  int id_max_l = 0;
  for (int i = 0; i < n; i++) {
    int l1, r1;
    cin >> l1 >> r1;
    if (max_l == l1) {
      cnt_max_l++;
    }
    if (max_l < l1) {
      sec_max_l = max_l;
      max_l = l1;
      cnt_max_l = 1;
      id_max_l = i;
    }
    if (sec_max_l < l1 && l1 != max_l) sec_max_l = l1;
    if (min_r == r1) {
      cnt_min_r++;
    }
    if (min_r > r1) {
      sec_min_r = min_r;
      min_r = r1;
      cnt_min_r = 1;
      id_min_r = i;
    }
    if (sec_min_r > r1 && r1 != min_r) sec_min_r = r1;
  }
  int bstAns = max(0, min_r - max_l);
  if (cnt_max_l == 1) {
    bstAns = max(bstAns, min_r - sec_max_l);
  }
  if (cnt_min_r == 1) {
    bstAns = max(bstAns, sec_min_r - max_l);
  }
  if (cnt_max_l == 1 && cnt_min_r == 1 && id_max_l == id_min_r) {
    bstAns = max(bstAns, sec_min_r - sec_max_l);
  }
  cout << bstAns;
}
