#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > vp(n), vp2, vp3;
  for (long long i = 0; i < n; i++) cin >> vp[i].first >> vp[i].second;
  vp2 = vp3 = vp;
  pair<long long, long long> p = {0, 1e9};
  for (long long i = 0; i < vp.size(); i++) {
    if (p.second < p.first) {
      vp3[i] = p;
      continue;
    } else
      p = vp3[i] = {max(vp3[i].first, p.first), min(vp3[i].second, p.second)};
  }
  p = {0, 1e9};
  for (long long i = vp.size() - 1; i >= 0; i--) {
    if (p.second < p.first) {
      vp2[i] = p;
      continue;
    } else
      p = vp2[i] = {max(vp2[i].first, p.first), min(vp2[i].second, p.second)};
  }
  long long ans = 0;
  for (long long i = 0; i < vp.size(); i++) {
    if (!i) {
      ans = max(ans, vp2[i + 1].second - vp2[i + 1].first + 1);
    } else if (i == vp.size() - 1) {
      ans = max(ans, vp3[i - 1].second - vp3[i - 1].first + 1);
    } else {
      p = vp2[i + 1];
      if (p.second >= p.first && vp3[i - 1].second >= vp3[i - 1].first) {
        p = {max(vp3[i - 1].first, p.first), min(vp3[i - 1].second, p.second)};
      } else {
        p = {1, 0};
      }
      ans = max(ans, p.second - p.first + 1);
    }
  }
  cout << max(0LL, ans - 1);
}
