import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N;
    scan(N);
    auto L = new int[](N);
    auto R = new int[](N);
    foreach (i ; 0 .. N) {
        scan(L[i], R[i]);
        R[i]++;
    }

    sort(zip(L, R));

    auto rf = new int[](N + 1);
    rf[0] = inf;
    foreach (i ; 1 .. N + 1) {
        rf[i] = min(rf[i - 1], R[i - 1]);
    }
    auto rr = new int[](N + 1);
    rr[N] = inf;
    foreach_reverse (i ; 0 .. N) {
        rr[i] = min(rr[i + 1], R[i]);
    }

    long ans;
    foreach (i ; 0 .. N - 1) {
        int Lz = L[N - 1], Rz = rr[i + 1];
        chmax(ans, R[i] - L[i] + max(0, min(Rz, rf[i]) - Lz));
        chmax(ans, max(0, rf[i + 1] - L[i]) + max(0, Rz - Lz));
    }
    writeln(ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}
