// AGC 040B
// DeP
#include <cstdio>
#include <climits>
#include <algorithm>
using namespace std;

const int MAXN = 1e5 + 5;

struct Item {
  int x, y;
  Item(int _x = 0, int _y = 0): x(_x), y(_y) { }
  bool operator < (const Item& rhs) const {
    return x > rhs.x || (x == rhs.x && y > rhs.y);
  }
} seg[MAXN], s[MAXN];

int n;
int pre[MAXN], suf[MAXN];

int main() {
  scanf("%d", &n);
  for (int L, R, i = 1; i <= n; ++i)
    scanf("%d%d", &L, &R), seg[i] = Item(L, R);

  int mxL = -1, mnR = INT_MAX, mxlgt = 0;
  for (int i = 1; i <= n; ++i) {
    mxlgt = max(mxlgt, seg[i].y - seg[i].x + 1);
    mxL = max(mxL, seg[i].x), mnR = min(mnR, seg[i].y);
  }

  int ans = mxlgt + max(0, mnR - mxL + 1);
  for (int i = 1; i <= n; ++i)
    s[i] = Item(max(0, seg[i].y - mxL + 1), max(0, mnR - seg[i].x + 1));
  sort(s + 1, s + 1 + n);
  suf[n] = s[n].y;
  for (int i = n - 1; i; --i)
    suf[i] = min(suf[i + 1], s[i].y);
  for (int i = 1; i < n; ++i)
    ans = max(ans, s[i].x + suf[i + 1]);

  printf("%d\n", ans);
  return 0;
}