N,M = list(map(int,input().split(' ')))

L = []

R = []



for i in range(M):

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

  L.append(l)

  R.append(r)

L.sort()

R.sort()

A = R[0] - L[-1] +1

print((max(A,0)))
N,M = list(map(int,input().split(' ')))

left,right = list(map(int,input().split(' ')))

for i in range(M-1):

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

  left = max(L,left)

  right = min(R,right)



print((max(right-left+1,0)))

N, M = list(map(int, input().split(" ")))
L = []
R = []
for i in range(M):
    l, r = list(map(int, input().split(" ")))
    L.append(l)
    R.append(r)
L.sort()
R.sort()
A = R[0] - L[-1] + 1
print((max(A, 0)))

N, M = list(map(int, input().split(" ")))
left, right = list(map(int, input().split(" ")))
for i in range(M - 1):
    L, R = list(map(int, input().split(" ")))
    left = max(L, left)
    right = min(R, right)
print((max(right - left + 1, 0)))

-L = [] -R = [] -for i in range(M): -    l, r = list(map(int, input().split(" "))) -    L.append(l) -    R.append(r) -L.sort() -R.sort() -A = R[0] - L[-1] + 1 -print((max(A, 0))) +left, right = list(map(int, input().split(" "))) +for i in range(M - 1): +    L, R = list(map(int, input().split(" "))) +    left = max(L, left) +    right = min(R, right) +print((max(right - left + 1, 0)))