#include <bits/stdc++.h>
using namespace std;
inline long long rint() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
inline long long gcd(long long a, long long b) {
  return (b) ? gcd(b, a % b) : a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long pow(long long a, long long b, long long q) {
  long long rtn = 1;
  while (b) {
    if (b & 1) rtn = rtn * a % q;
    a = a * a % q;
    b >>= 1;
  }
  return rtn;
}
inline long long mysqrt(long long n) {
  long long x = sqrt(n);
  while (x * x < n) x++;
  while (x * x > n) x--;
  return x;
}
const long long mod = 1e9 + 7;
const long long N = 3e5 + 5;
pair<int, int> v[N];
pair<int, int> a[N];
pair<int, int> b[N];
int main() {
  int n = rint();
  for (int i = 1; i <= n; i++) v[i].first = rint(), v[i].second = rint() - 1;
  int l = 0, r = 1e9;
  for (int i = n; i >= 1; i--) {
    l = max(l, v[i].first);
    r = min(r, v[i].second);
    if (l <= r)
      a[i] = {l, r};
    else
      a[i] = {-1, -1};
  }
  l = 0, r = 1e9;
  for (int i = 1; i <= n; i++) {
    l = max(l, v[i].first);
    r = min(r, v[i].second);
    if (l <= r)
      b[i] = {l, r};
    else
      b[i] = {-1, -1};
  }
  a[n + 1] = {0, 1e9};
  b[0] = {0, 1e9};
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i + 1].first == -1 || b[i - 1].first == -1) continue;
    int zuo = max(a[i + 1].first, b[i - 1].first);
    int you = min(a[i + 1].second, b[i - 1].second);
    if (zuo <= you) res = max(res, you - zuo + 1);
  }
  cout << res << "\n";
}
