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

info=[]

for i in range(m):

    info.append(list(map(int,input().split())))

start,goal=info[0][0],info[0][1]

c=0



for i in range(1,m):

    start=max(start,info[i][0])

    goal=min(goal,info[i][1])

    if start>goal:

        c=1

        break

    

if c==0:

    print((goal-start+1))

else:

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

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



for i in range(m-1):

    l,r=list(map(int,input().split()))

    if r<L:

        L,R=0,-1

        break

    if R<l:

        L,R=0,-1

        break

    L=max(L,l)

    R=min(R,r)

print((R-L+1))
n, m = list(map(int, input().split()))
info = []
for i in range(m):
    info.append(list(map(int, input().split())))
start, goal = info[0][0], info[0][1]
c = 0
for i in range(1, m):
    start = max(start, info[i][0])
    goal = min(goal, info[i][1])
    if start > goal:
        c = 1
        break
if c == 0:
    print((goal - start + 1))
else:
    print((0))

n, m = list(map(int, input().split()))
L, R = list(map(int, input().split()))
for i in range(m - 1):
    l, r = list(map(int, input().split()))
    if r < L:
        L, R = 0, -1
        break
    if R < l:
        L, R = 0, -1
        break
    L = max(L, l)
    R = min(R, r)
print((R - L + 1))

-info = [] -for i in range(m): -    info.append(list(map(int, input().split()))) -start, goal = info[0][0], info[0][1] -c = 0 -for i in range(1, m): -    start = max(start, info[i][0]) -    goal = min(goal, info[i][1]) -    if start > goal: -        c = 1 +L, R = list(map(int, input().split())) +for i in range(m - 1): +    l, r = list(map(int, input().split())) +    if r < L: +        L, R = 0, -1 -if c == 0: -    print((goal - start + 1)) -else: -    print((0)) +    if R < l: +        L, R = 0, -1 +        break +    L = max(L, l) +    R = min(R, r) +print((R - L + 1))