#include <bits/stdc++.h>
using namespace std;
long long c[26] = {0};
string s;
pair<long long, long long> intersection(pair<long long, long long> a,
                                        pair<long long, long long> b) {
  pair<long long, long long> p;
  p.first = max(a.first, b.first);
  p.second = min(a.second, b.second);
  return p;
}
void solve() {
  long long n, m, x, y, mx = 0, i = 0, j = 0, k, f = 0, ten = 10;
  cin >> n;
  vector<pair<long long, long long> > a(n), pre(n), suff(n);
  for (i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  pre[0].first = INT_MIN;
  pre[0].second = INT_MAX;
  suff[n - 1].first = INT_MIN;
  suff[n - 1].second = INT_MAX;
  for (i = 1; i < n; i++) {
    pair<long long, long long> p = intersection(pre[i - 1], a[i - 1]);
    pre[i] = p;
  }
  for (i = n - 2; i >= 0; i--) {
    pair<long long, long long> p = intersection(suff[i + 1], a[i + 1]);
    suff[i] = p;
  }
  for (int i = 0; i < n; i++) {
    pair<long long, long long> p = intersection(pre[i], suff[i]);
    if ((p.second - p.first) > mx) mx = (p.second - p.first);
  }
  cout << mx;
}
int main() {
  long long t;
  solve();
}
