#include <bits/stdc++.h>
using namespace std;
int const MOD = 1e9 + 7;
double const PI = acos(-1);
long long const oo = 8e18;
int const N = 3e5 + 100;
int const M = 1e6 + 100;
int n;
pair<int, int> a[N], p1[N], p2[N];
pair<int, int> intersection(pair<int, int> x, pair<int, int> y) {
  if (x.second < y.first || y.second < x.first)
    return {-1, -1};
  else
    return {max(x.first, y.first), min(x.second, y.second)};
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d%d", &a[i].first, &a[i].second);
  for (int i = 0; i < n; ++i) {
    if (i == 0)
      p1[i] = a[i];
    else {
      p1[i] = intersection(a[i], p1[i - 1]);
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    if (i == n - 1)
      p2[i] = a[i];
    else {
      p2[i] = intersection(a[i], p2[i + 1]);
    }
  }
  int mx = 0;
  for (int i = 0; i < n; ++i) {
    pair<int, int> temp;
    if (i == 0) {
      temp = p2[i + 1];
    } else if (i == n - 1) {
      temp = p1[i - 1];
    } else {
      temp = intersection(p1[i - 1], p2[i + 1]);
    }
    mx = max(mx, temp.second - temp.first);
  }
  cout << mx << endl;
  return 0;
}
