#include <bits/stdc++.h>
using namespace std;
struct Event {
  int c, t;
  bool operator<(const Event &e) const {
    if (c != e.c) return (c < e.c);
    return (t < e.t);
  }
};
int go(vector<Event> &A, int n) {
  int cnt = 0, res = 0, c1 = 0, c2 = 0;
  for (int i = 0; i < A.size(); i++) {
    if (A[i].t == 0) {
      cnt++;
      if (cnt == n) c1 = A[i].c;
    } else {
      if (cnt == n) c2 = A[i].c;
      cnt--;
    }
    res = max(res, cnt);
  }
  if (res < n) return 0;
  return c2 - c1;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<int, int> > C;
  vector<Event> A, B;
  int a1 = -1, a2 = (1 << 30), b1 = -1, b2 = (1 << 30);
  int id1 = 0, id2 = 0;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    C.push_back({l, r});
    if (l >= a1) {
      if (l == a1) {
        if (r < a2) a2 = r, id1 = i;
      } else {
        a1 = l;
        a2 = r;
        id1 = i;
      }
    }
    if (r <= b2) {
      if (r == b2) {
        if (l > b1) b1 = l, id2 = i;
      } else {
        b1 = l;
        b2 = r;
        id2 = i;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    int l = C[i].first, r = C[i].second;
    if (i != id1) {
      A.push_back({l, 0});
      A.push_back({r, 1});
    }
    if (i != id2) {
      B.push_back({l, 0});
      B.push_back({r, 1});
    }
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  cout << max(go(A, n - 1), go(B, n - 1)) << endl;
}
