#include <bits/stdc++.h>
using namespace std;
const long long inf = 9.2e18;
const int maxn = 3e5 + 70;
const int INF = 2.1e9;
const int maxm = 1e6 + 70;
const int MOD = 1e9 + 7;
const double eps = 1e-7;
const double PI = acos(-1.0);
int n, m, k;
int L[maxn], R[maxn], r1[maxn], r2[maxn];
bool cmp1(int x, int y) { return L[x] < L[y]; }
bool cmp2(int x, int y) { return R[x] < R[y]; }
int main() {
  while (cin >> n) {
    for (int i = 0; i < n; i++) scanf("%d%d", &L[i], &R[i]);
    for (int i = 0; i < n; i++) r1[i] = r2[i] = i;
    sort(r1, r1 + n, cmp1);
    sort(r2, r2 + n, cmp2);
    int l = L[r1[n - 1]], r = R[r2[0]];
    int ans = max(r - l, 0);
    if (r1[n - 1] == r2[0]) {
      l = L[r1[n - 2]], r = R[r2[1]];
      ans = max(ans, r - l);
    } else {
      l = L[r1[n - 2]], r = R[r2[0]];
      ans = max(ans, r - l);
      l = L[r1[n - 1]], r = R[r2[1]];
      ans = max(ans, r - l);
    }
    cout << ans << endl;
  }
  return 0;
}
