#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)(2 * 1e5 + 10);
long long mult(long long a, long long b, long long p) {
  return ((a % p) * (b % p)) % p;
}
long long add(long long a, long long b, long long p) {
  return (a % p + b % p) % p;
}
long long fpow(long long n, long long k, long long p) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
void SieveOfEratosthenes(long long n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long i = p * 2; i <= n; i += p) prime[i] = false;
    }
  }
  for (long long p = 2; p <= n; p++)
    if (prime[p]) cout << p << " ";
}
pair<long long, long long> aagese[400003], suff[400003];
pair<long long, long long> a[400003];
signed main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  suff[n - 1].first = a[n - 1].first;
  suff[n - 1].second = a[n - 1].second;
  for (long long i = n - 2; i >= 0; i--) {
    long long st = a[i].first;
    long long kitne = suff[i + 1].first;
    long long en = a[i].second;
    long long bada = suff[i + 1].second;
    if (kitne == -1) {
      suff[i].second = -1;
      suff[i].first = -1;
      continue;
    }
    if (bada < st || en < kitne) {
      suff[i].second = -1;
      suff[i].first = -1;
    } else {
      suff[i].second = min(en, bada);
      suff[i].first = max(st, kitne);
    }
  }
  long long raj[n];
  for (long long i = 0; i < n; i++) raj[i] = i;
  aagese[0].first = a[0].first;
  aagese[0].second = a[0].second;
  for (long long i = 1; i <= n - 1; i++) {
    long long st = a[i].first;
    long long kitne = aagese[i - 1].first;
    long long bada = aagese[i - 1].second;
    long long en = a[i].second;
    if (kitne == -1) {
      aagese[i].second = -1;
      aagese[i].first = -1;
      continue;
    }
    if (bada < st || en < kitne) {
      aagese[i].second = -1;
      aagese[i].first = -1;
    } else {
      aagese[i].second = min(en, bada);
      aagese[i].first = max(st, kitne);
    }
  }
  long long maxx = -1;
  for (long long i = 0; i < n; i++) {
    if (i == n - 1) {
      long long en1 = aagese[i - 1].second;
      long long st1 = aagese[i - 1].first;
      if (st1 == -1) {
        maxx = max(maxx, (long long)0);
      } else {
        maxx = max(maxx, abs(st1 - en1));
      }
    } else if (i == 0) {
      long long st1 = suff[i + 1].first;
      long long en1 = suff[i + 1].second;
      if (st1 == -1) {
        maxx = max(maxx, (long long)0);
      } else {
        maxx = max(maxx, abs(st1 - en1));
      }
    } else {
      long long st2 = suff[i + 1].first;
      long long st1 = aagese[i - 1].first;
      long long en2 = suff[i + 1].second;
      long long en1 = aagese[i - 1].second;
      if (st1 == -1 || st2 == -1) {
        maxx = max(maxx, (long long)0);
        continue;
      }
      if (en2 < st1 || en1 < st2) {
        maxx = max(maxx, (long long)0);
        continue;
      } else {
        long long st = max(st1, st2);
        long long en = min(en1, en2);
        maxx = max(maxx, abs(st - en));
      }
    }
  }
  cout << maxx << "\n";
  return 0;
}
