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



left = 1

right = N



for i in range(M):

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

    left = max(left, L)

    right = min(right, R)



print((max(right - left + 1, 0)))
N, M = list(map(int, input().split()))



L = [None] * M

R = [None] * M



for i in range(M):

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

    L[i] = l

    R[i] = r



L_max = max(L)

R_min = min(R)



if L_max > R_min:

    print((0))

else:

    print((R_min - L_max + 1))

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

N, M = list(map(int, input().split()))
L = [None] * M
R = [None] * M
for i in range(M):
    l, r = list(map(int, input().split()))
    L[i] = l
    R[i] = r
L_max = max(L)
R_min = min(R)
if L_max > R_min:
    print((0))
else:
    print((R_min - L_max + 1))

-left = 1 -right = N +L = [None] * M +R = [None] * M -    L, R = list(map(int, input().split())) -    left = max(left, L) -    right = min(right, R) -print((max(right - left + 1, 0))) +    l, r = list(map(int, input().split())) +    L[i] = l +    R[i] = r +L_max = max(L) +R_min = min(R) +if L_max > R_min: +    print((0)) +else: +    print((R_min - L_max + 1))