#include <bits/stdc++.h>
using namespace std;

const int N = 100010;
int a[N], b[N], c[N], d[N];

struct Node {
    int l, r;
} w[N];

inline bool cmp(Node a, Node b)
{
    if (a.l == b.l) return a.r < b.r;
    return a.l < b.l;
}

int main()
{
    register int n, ans = 0;
    scanf("%d", &n);
    for (register int i = 1; i <= n; ++i) {
        scanf("%d %d", &w[i].l, &w[i].r);
    }
    sort(w + 1, w + n + 1, cmp);
    a[1] = w[1].l, b[1] = w[1].r;
    for (register int i = 2; i <= n; ++i) {
        a[i] = max(a[i - 1], w[i].l);
        b[i] = min(b[i - 1], w[i].r);
    }
    c[n] = w[n].l, d[n] = w[n].r;
    for (register int i = n - 1; i >= 1; --i) {
        c[i] = max(c[i + 1], w[i].l);
        d[i] = min(d[i + 1], w[i].r);
    }
    for (register int i = 1; i < n; ++i) {
        ans = max(ans, max(0, b[i] - a[i] + 1) + max(0, d[i + 1] - c[i + 1] + 1));
    }
    for (register int i = 1; i <= n; ++i) {
        ans = max(ans, w[i].r - w[i].l + 1 + max(0, min(b[i], d[i]) - max(a[i], c[i]) + 1));
    }
    printf("%d\n", ans);
    return 0;
}