import sys

input = sys.stdin.readline

N = int(eval(input()))

mG = [tuple(map(int, input().split())) for _ in range(N)]



mG.sort(key=lambda x: x[1], reverse=True)

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



# print(mG)###



vA1 = []

vL1 = []

vR1 = []

L = -1

R = 10**9 + 1



for l,r in mG[:-1]:

    L = max(L, l)

    R = min(R, r)

    vL1.append(L)

    vR1.append(R)

    vA1.append(R-L+1)



# print(vA1)###



vA2 = []

vL2 = []

vR2 = []

L = -1

R = 10**9 + 1



for l,r in mG[:0:-1]:

    L = max(L, l)

    R = min(R, r)

    vL2.append(L)

    vR2.append(R)

    vA2.append(R-L+1)



# print(vA2)###



M1 = max(a+b for a,b in zip(vA1, vA2[::-1]))



# pick max1

# and all others to 2

k = 0

idm = -1

for i,(l,r) in enumerate(mG):

    d = r-l+1

    if d > k:

        k = d

        idm = i

    

L = -1

R = 10**9 + 1



for i,(l,r) in enumerate(mG):

    if i==idm:

      continue

    L = max(L, l)

    R = min(R, r)



M2 = k + max(0, R-L+1)



print((max(M1,M2)))
import sys

from operator import itemgetter as ITEM

input = sys.stdin.readline

N = int(eval(input()))

mG = [tuple(map(int, input().split())) for _ in range(N)]



mG.sort(key=ITEM(1), reverse=True)

mG.sort(key=ITEM(0))



INF = 1000100100



vA1 = []

L = -1

R = INF

for l,r in mG[:-1]:

    L = max(L, l)

    R = min(R, r)

    vA1.append(R-L+1)



vA2 = []

L = -1

R = INF

for l,r in mG[:0:-1]:

    L = max(L, l)

    R = min(R, r)

    vA2.append(R-L+1)



M1 = max(a+b for a,b in zip(vA1, vA2[::-1]))



# pick max1

# and all others to 2

k = 0

idm = -1

for i,(l,r) in enumerate(mG):

    d = r-l+1

    if d > k:

        k = d

        idm = i



L = -1

R = INF

for i,(l,r) in enumerate(mG):

    if i==idm:

        continue

    L = max(L, l)

    R = min(R, r)



M2 = k + max(0, R-L+1)



print((max(M1,M2)))

import sys

input = sys.stdin.readline
N = int(eval(input()))
mG = [tuple(map(int, input().split())) for _ in range(N)]
mG.sort(key=lambda x: x[1], reverse=True)
mG.sort(key=lambda x: x[0])
# print(mG)###
vA1 = []
vL1 = []
vR1 = []
L = -1
R = 10**9 + 1
for l, r in mG[:-1]:
    L = max(L, l)
    R = min(R, r)
    vL1.append(L)
    vR1.append(R)
    vA1.append(R - L + 1)
# print(vA1)###
vA2 = []
vL2 = []
vR2 = []
L = -1
R = 10**9 + 1
for l, r in mG[:0:-1]:
    L = max(L, l)
    R = min(R, r)
    vL2.append(L)
    vR2.append(R)
    vA2.append(R - L + 1)
# print(vA2)###
M1 = max(a + b for a, b in zip(vA1, vA2[::-1]))
# pick max1
# and all others to 2
k = 0
idm = -1
for i, (l, r) in enumerate(mG):
    d = r - l + 1
    if d > k:
        k = d
        idm = i
L = -1
R = 10**9 + 1
for i, (l, r) in enumerate(mG):
    if i == idm:
        continue
    L = max(L, l)
    R = min(R, r)
M2 = k + max(0, R - L + 1)
print((max(M1, M2)))

import sys
from operator import itemgetter as ITEM

input = sys.stdin.readline
N = int(eval(input()))
mG = [tuple(map(int, input().split())) for _ in range(N)]
mG.sort(key=ITEM(1), reverse=True)
mG.sort(key=ITEM(0))
INF = 1000100100
vA1 = []
L = -1
R = INF
for l, r in mG[:-1]:
    L = max(L, l)
    R = min(R, r)
    vA1.append(R - L + 1)
vA2 = []
L = -1
R = INF
for l, r in mG[:0:-1]:
    L = max(L, l)
    R = min(R, r)
    vA2.append(R - L + 1)
M1 = max(a + b for a, b in zip(vA1, vA2[::-1]))
# pick max1
# and all others to 2
k = 0
idm = -1
for i, (l, r) in enumerate(mG):
    d = r - l + 1
    if d > k:
        k = d
        idm = i
L = -1
R = INF
for i, (l, r) in enumerate(mG):
    if i == idm:
        continue
    L = max(L, l)
    R = min(R, r)
M2 = k + max(0, R - L + 1)
print((max(M1, M2)))

+from operator import itemgetter as ITEM -mG.sort(key=lambda x: x[1], reverse=True) -mG.sort(key=lambda x: x[0]) -# print(mG)### +mG.sort(key=ITEM(1), reverse=True) +mG.sort(key=ITEM(0)) +INF = 1000100100 -vL1 = [] -vR1 = [] -R = 10**9 + 1 +R = INF -    vL1.append(L) -    vR1.append(R) -# print(vA1)### -vL2 = [] -vR2 = [] -R = 10**9 + 1 +R = INF -    vL2.append(L) -    vR2.append(R) -# print(vA2)### -R = 10**9 + 1 +R = INF