#include <bits/stdc++.h>
using namespace std;
int n, m, q;
pair<int, int> t[300100];
pair<int, int> up[300100];
pair<int, int> down[300100];
pair<int, int> inter(pair<int, int> a, pair<int, int> b) {
  int f = max(a.first, b.first);
  int s = min(a.second, b.second);
  pair<int, int> res = {f, s};
  return res;
}
long long int len(pair<int, int> a) {
  int res = a.second - a.first;
  if (res < 0) res = 0;
  return res;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> t[i].first >> t[i].second;
  down[0] = t[0];
  up[n - 1] = t[n - 1];
  for (int i = 0; i < n - 1; i++) down[i + 1] = inter(down[i], t[i + 1]);
  for (int i = n - 1; i > 0; i--) up[i - 1] = inter(up[i], t[i - 1]);
  long long int ma = -1;
  ma = max(ma, len(up[1]));
  ma = max(ma, len(down[n - 2]));
  for (int i = 1; i < n - 1; i++) {
    long long int a = len(inter(down[i - 1], up[i + 1]));
    ma = max(ma, a);
  }
  cout << ma;
  return 0;
}
