#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long mod = 1000000007;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const int N = 300100;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int prefl[N], prefr[N];
int sufl[N], sufr[N];
int l[N], r[N];
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> l[i] >> r[i];
  prefl[0] = 0, prefr[0] = inf;
  sufl[n + 1] = 0, sufr[n + 1] = inf;
  for (int i = 1; i <= n; i++) {
    prefl[i] = max(prefl[i - 1], l[i]);
    prefr[i] = min(prefr[i - 1], r[i]);
  }
  for (int i = n; i >= 1; i--) {
    sufl[i] = max(sufl[i + 1], l[i]);
    sufr[i] = min(sufr[i + 1], r[i]);
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    int lo = max(prefl[i - 1], sufl[i + 1]);
    int hi = min(prefr[i - 1], sufr[i + 1]);
    if (lo > hi) continue;
    mx = max(mx, hi - lo);
  }
  cout << mx << "\n";
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  ;
  int t_ = 1;
  while (t_--) solve();
  return 0;
}
