import sys

input = sys.stdin.readline



def solve():

    N = int(eval(input()))

    LRs = []

    Ls, Rs = [], []

    for _ in range(N):

        L, R = list(map(int, input().split()))

        LRs.append((L, R))

        Ls.append(L)

        Rs.append(R)



    Ls.sort(reverse=True)

    Rs.sort()



    maxL, maxL2 = Ls[:2]

    minR, minR2 = Rs[:2]



    # 1個にする要素を全探索

    ans = 0

    for L, R in LRs:

        num = R-L+1

        A, B = maxL, minR

        if L == maxL:

            A = maxL2

        if R == minR:

            B = minR2

        num += max(0, B-A+1)

        ans = max(ans, num)



    # 区切りを全探索

    LRs.sort(key=lambda x: x[0])



    minR = LRs[0][1]

    accMinRs = [minR]

    for L, R in LRs[1:]:

        minR = min(minR, R)

        accMinRs.append(minR)

    minR = LRs[-1][1]

    accMinRRevs = [minR]

    for L, R in reversed(LRs[:-1]):

        minR = min(minR, R)

        accMinRRevs.append(minR)

    accMinRRevs = accMinRRevs[::-1]



    for i in range(N-1):

        num = max(0, accMinRs[i] - LRs[i][0] + 1)

        num += max(0, accMinRRevs[i+1] - LRs[-1][0] + 1)

        ans = max(ans, num)



    # 区切りを全探索

    LRs.sort(key=lambda x: x[1])



    maxL = LRs[0][0]

    accMaxLs = [maxL]

    for L, R in LRs[1:]:

        maxL = max(maxL, L)

        accMaxLs.append(maxL)

    maxL = LRs[-1][0]

    accMaxLRevs = [maxL]

    for L, R in reversed(LRs[:-1]):

        maxL = max(maxL, L)

        accMaxLRevs.append(maxL)

    accMaxLRevs = accMaxLRevs[::-1]



    for i in range(N-1):

        num = max(0, LRs[0][1] - accMaxLs[i] + 1)

        num += max(0, LRs[i+1][1] - accMaxLRevs[i+1] + 1)

        ans = max(ans, num)



    print(ans)





solve()

import sys

input = sys.stdin.readline



maxLR = 10**9



N = int(eval(input()))

LRs = []

for _ in range(N):

    L, R = list(map(int, input().split()))

    LRs.append((L, R))



LRs.sort()



accMinRs = [LRs[0][1]]

for L, R in LRs[1:]:

    accMinRs.append(min(accMinRs[-1], R))



accMinRRevs = [LRs[-1][1]]

for L, R in reversed(LRs[:-1]):

    accMinRRevs.append(min(accMinRRevs[-1], R))

accMinRRevs.reverse()



L2 = LRs[-1][0]

ans = 0

for x in range(N-1):

    L1, R1 = LRs[x]

    L0 = LRs[x-1][0] if x > 0 else 0

    R0 = accMinRs[x] if x > 0 else maxLR

    R2 = accMinRRevs[x+1]

    score1 = max(0, min(R0, R1)-max(L0, L1)+1) + max(0, R2-L2+1)

    score2 = max(0, R1-L1+1) + max(0, min(R0, R2)-max(L0, L2)+1)

    ans = max(ans, score1, score2)



print(ans)

import sys

input = sys.stdin.readline


def solve():
    N = int(eval(input()))
    LRs = []
    Ls, Rs = [], []
    for _ in range(N):
        L, R = list(map(int, input().split()))
        LRs.append((L, R))
        Ls.append(L)
        Rs.append(R)
    Ls.sort(reverse=True)
    Rs.sort()
    maxL, maxL2 = Ls[:2]
    minR, minR2 = Rs[:2]
    # 1個にする要素を全探索
    ans = 0
    for L, R in LRs:
        num = R - L + 1
        A, B = maxL, minR
        if L == maxL:
            A = maxL2
        if R == minR:
            B = minR2
        num += max(0, B - A + 1)
        ans = max(ans, num)
    # 区切りを全探索
    LRs.sort(key=lambda x: x[0])
    minR = LRs[0][1]
    accMinRs = [minR]
    for L, R in LRs[1:]:
        minR = min(minR, R)
        accMinRs.append(minR)
    minR = LRs[-1][1]
    accMinRRevs = [minR]
    for L, R in reversed(LRs[:-1]):
        minR = min(minR, R)
        accMinRRevs.append(minR)
    accMinRRevs = accMinRRevs[::-1]
    for i in range(N - 1):
        num = max(0, accMinRs[i] - LRs[i][0] + 1)
        num += max(0, accMinRRevs[i + 1] - LRs[-1][0] + 1)
        ans = max(ans, num)
    # 区切りを全探索
    LRs.sort(key=lambda x: x[1])
    maxL = LRs[0][0]
    accMaxLs = [maxL]
    for L, R in LRs[1:]:
        maxL = max(maxL, L)
        accMaxLs.append(maxL)
    maxL = LRs[-1][0]
    accMaxLRevs = [maxL]
    for L, R in reversed(LRs[:-1]):
        maxL = max(maxL, L)
        accMaxLRevs.append(maxL)
    accMaxLRevs = accMaxLRevs[::-1]
    for i in range(N - 1):
        num = max(0, LRs[0][1] - accMaxLs[i] + 1)
        num += max(0, LRs[i + 1][1] - accMaxLRevs[i + 1] + 1)
        ans = max(ans, num)
    print(ans)


solve()

import sys

input = sys.stdin.readline
maxLR = 10**9
N = int(eval(input()))
LRs = []
for _ in range(N):
    L, R = list(map(int, input().split()))
    LRs.append((L, R))
LRs.sort()
accMinRs = [LRs[0][1]]
for L, R in LRs[1:]:
    accMinRs.append(min(accMinRs[-1], R))
accMinRRevs = [LRs[-1][1]]
for L, R in reversed(LRs[:-1]):
    accMinRRevs.append(min(accMinRRevs[-1], R))
accMinRRevs.reverse()
L2 = LRs[-1][0]
ans = 0
for x in range(N - 1):
    L1, R1 = LRs[x]
    L0 = LRs[x - 1][0] if x > 0 else 0
    R0 = accMinRs[x] if x > 0 else maxLR
    R2 = accMinRRevs[x + 1]
    score1 = max(0, min(R0, R1) - max(L0, L1) + 1) + max(0, R2 - L2 + 1)
    score2 = max(0, R1 - L1 + 1) + max(0, min(R0, R2) - max(L0, L2) + 1)
    ans = max(ans, score1, score2)
print(ans)

- - -def solve(): -    N = int(eval(input())) -    LRs = [] -    Ls, Rs = [], [] -    for _ in range(N): -        L, R = list(map(int, input().split())) -        LRs.append((L, R)) -        Ls.append(L) -        Rs.append(R) -    Ls.sort(reverse=True) -    Rs.sort() -    maxL, maxL2 = Ls[:2] -    minR, minR2 = Rs[:2] -    # 1個にする要素を全探索 -    ans = 0 -    for L, R in LRs: -        num = R - L + 1 -        A, B = maxL, minR -        if L == maxL: -            A = maxL2 -        if R == minR: -            B = minR2 -        num += max(0, B - A + 1) -        ans = max(ans, num) -    # 区切りを全探索 -    LRs.sort(key=lambda x: x[0]) -    minR = LRs[0][1] -    accMinRs = [minR] -    for L, R in LRs[1:]: -        minR = min(minR, R) -        accMinRs.append(minR) -    minR = LRs[-1][1] -    accMinRRevs = [minR] -    for L, R in reversed(LRs[:-1]): -        minR = min(minR, R) -        accMinRRevs.append(minR) -    accMinRRevs = accMinRRevs[::-1] -    for i in range(N - 1): -        num = max(0, accMinRs[i] - LRs[i][0] + 1) -        num += max(0, accMinRRevs[i + 1] - LRs[-1][0] + 1) -        ans = max(ans, num) -    # 区切りを全探索 -    LRs.sort(key=lambda x: x[1]) -    maxL = LRs[0][0] -    accMaxLs = [maxL] -    for L, R in LRs[1:]: -        maxL = max(maxL, L) -        accMaxLs.append(maxL) -    maxL = LRs[-1][0] -    accMaxLRevs = [maxL] -    for L, R in reversed(LRs[:-1]): -        maxL = max(maxL, L) -        accMaxLRevs.append(maxL) -    accMaxLRevs = accMaxLRevs[::-1] -    for i in range(N - 1): -        num = max(0, LRs[0][1] - accMaxLs[i] + 1) -        num += max(0, LRs[i + 1][1] - accMaxLRevs[i + 1] + 1) -        ans = max(ans, num) -    print(ans) - - -solve() +maxLR = 10**9 +N = int(eval(input())) +LRs = [] +for _ in range(N): +    L, R = list(map(int, input().split())) +    LRs.append((L, R)) +LRs.sort() +accMinRs = [LRs[0][1]] +for L, R in LRs[1:]: +    accMinRs.append(min(accMinRs[-1], R)) +accMinRRevs = [LRs[-1][1]] +for L, R in reversed(LRs[:-1]): +    accMinRRevs.append(min(accMinRRevs[-1], R)) +accMinRRevs.reverse() +L2 = LRs[-1][0] +ans = 0 +for x in range(N - 1): +    L1, R1 = LRs[x] +    L0 = LRs[x - 1][0] if x > 0 else 0 +    R0 = accMinRs[x] if x > 0 else maxLR +    R2 = accMinRRevs[x + 1] +    score1 = max(0, min(R0, R1) - max(L0, L1) + 1) + max(0, R2 - L2 + 1) +    score2 = max(0, R1 - L1 + 1) + max(0, min(R0, R2) - max(L0, L2) + 1) +    ans = max(ans, score1, score2) +print(ans)