#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  vector<pair<int, int>> v, psum, ssum;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    v.push_back(make_pair(a, b));
  }
  ssum.resize(t + 1);
  psum.push_back(v[0]);
  ssum[t - 1] = v[t - 1];
  for (int i = 1; i < t; i++) {
    psum.push_back(make_pair(max(v[i].first, psum[i - 1].first),
                             min(v[i].second, psum[i - 1].second)));
  }
  for (int i = t - 1; i > 0; i--)
    ssum[i - 1] = (make_pair(max(ssum[i].first, v[i - 1].first),
                             min(ssum[i].second, v[i - 1].second)));
  int ans = 0;
  for (int i = 1; i < t - 1; i++) {
    pair<int, int> k = make_pair(max(psum[i - 1].first, ssum[i + 1].first),
                                 min(psum[i - 1].second, ssum[i + 1].second));
    ans = max(ans, k.second - k.first);
  }
  if (ans < psum[t - 2].second - psum[t - 2].first)
    ans = psum[t - 2].second - psum[t - 2].first;
  if (ans < ssum[1].second - ssum[1].first)
    ans = ssum[1].second - ssum[1].first;
  printf("%d\n", ans);
  return 0;
}
