n, m=list(map(int, input().split()))

grid = []

for i in range(m):

    array = list(map(int, input().strip().split()))

    grid.append(array)





maxa,mina=grid[0]

for i in range(1,m):

    if maxa<grid[i][0]:

        maxa=grid[i][0]

    if mina>grid[i][1]:

        mina=grid[i][1]



v=mina-maxa+1

if v>0:

    print(v)

else:

    print((0))
n,m = list(map(int, input().split()))

LR = [list(map(int, input().split())) for _ in range(m)]

L = max([i[0] for i in LR])

R = min([i[1] for i in LR])

print((max(R-L+1,0)))
n, m = list(map(int, input().split()))
grid = []
for i in range(m):
    array = list(map(int, input().strip().split()))
    grid.append(array)
maxa, mina = grid[0]
for i in range(1, m):
    if maxa < grid[i][0]:
        maxa = grid[i][0]
    if mina > grid[i][1]:
        mina = grid[i][1]
v = mina - maxa + 1
if v > 0:
    print(v)
else:
    print((0))

n, m = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(m)]
L = max([i[0] for i in LR])
R = min([i[1] for i in LR])
print((max(R - L + 1, 0)))

-grid = [] -for i in range(m): -    array = list(map(int, input().strip().split())) -    grid.append(array) -maxa, mina = grid[0] -for i in range(1, m): -    if maxa < grid[i][0]: -        maxa = grid[i][0] -    if mina > grid[i][1]: -        mina = grid[i][1] -v = mina - maxa + 1 -if v > 0: -    print(v) -else: -    print((0)) +LR = [list(map(int, input().split())) for _ in range(m)] +L = max([i[0] for i in LR]) +R = min([i[1] for i in LR]) +print((max(R - L + 1, 0)))