#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
using namespace std;
struct data {
  long start, endi;
};
bool cmp(data a, data b) {
  if (a.start == b.start)
    return a.endi < b.endi;
  else
    return a.start < b.start;
}
bool cmp1(data a, data b) {
  if (a.start == b.start)
    return a.endi > b.endi;
  else
    return a.start > b.start;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  for (int i1 = 0; i1 < t; i1++) {
    long n;
    cin >> n;
    vector<data> arr(n), arr1;
    for (int i = 0; i < n; i++) cin >> arr[i].start >> arr[i].endi;
    sort(arr.begin(), arr.end(), cmp);
    arr1 = arr;
    sort(arr1.begin(), arr1.end(), cmp1);
    vector<data> length(n);
    int curstart, curendi;
    curstart = arr[0].start;
    curendi = arr[0].endi;
    length[0].start = curstart;
    length[0].endi = curendi;
    for (int i = 1; i < n; i++) {
      if (arr[i].start > curstart) curstart = arr[i].start;
      if (arr[i].endi < curendi) curendi = arr[i].endi;
      length[i].start = curstart;
      length[i].endi = curendi;
    }
    long mini = INT_MAX;
    ;
    for (int i = 0; i < n; i++)
      mini = min(mini, length[i].endi - length[i].start);
    for (int i = 0; i < n; i++) {
      if (length[i].endi - length[i].start == mini) {
        arr.erase(arr.begin() + i);
        break;
      }
    }
    curstart = arr[0].start;
    curendi = arr[0].endi;
    for (int i = 1; i < arr.size(); i++) {
      if (arr[i].start > curstart) curstart = arr[i].start;
      if (arr[i].endi < curendi) curendi = arr[i].endi;
    }
    long ans1 = max(0, curendi - curstart);
    curstart = arr1[0].start;
    curendi = arr1[0].endi;
    length[0].start = curstart;
    length[0].endi = curendi;
    for (int i = 1; i < n; i++) {
      if (arr1[i].start > curstart) curstart = arr1[i].start;
      if (arr1[i].endi < curendi) curendi = arr1[i].endi;
      length[i].start = curstart;
      length[i].endi = curendi;
    }
    long mini1 = INT_MAX;
    ;
    for (int i = 0; i < n; i++)
      mini1 = min(mini1, length[i].endi - length[i].start);
    for (int i = 0; i < n; i++) {
      if (length[i].endi - length[i].start == mini) {
        arr1.erase(arr1.begin() + i);
        break;
      }
    }
    curstart = arr1[0].start;
    curendi = arr1[0].endi;
    for (int i = 1; i < arr1.size(); i++) {
      if (arr1[i].start > curstart) curstart = arr1[i].start;
      if (arr1[i].endi < curendi) curendi = arr1[i].endi;
    }
    long ans2 = max(0, curendi - curstart);
    cout << max(ans1, ans2);
  }
}
