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

w=[list(map(int, input().split())) for i in range(M)]

R_min=10**6

L_max=0

cnt=0



for i in range(M):

    if w[i][1]<=R_min:

        R_min=w[i][1]



for i in range(M):

    if w[i][0]>=L_max:

        L_max=w[i][0]



for num in range(1, N+1):

    if L_max<= num <= R_min:

        cnt+=1

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

gate=[]



for i in range(m):

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

    gate.append((L, R))



L_max=0

R_min=10**6

for i in range(m):

    if gate[i][0]>L_max:

        L_max=gate[i][0]



for i in range(m):

    if gate[i][1]<R_min:

        R_min=gate[i][1]





ans=0



for i in range(1, n+1):

    if L_max<=i<=R_min:

        ans+=1



print(ans)
N, M = list(map(int, input().split()))
w = [list(map(int, input().split())) for i in range(M)]
R_min = 10**6
L_max = 0
cnt = 0
for i in range(M):
    if w[i][1] <= R_min:
        R_min = w[i][1]
for i in range(M):
    if w[i][0] >= L_max:
        L_max = w[i][0]
for num in range(1, N + 1):
    if L_max <= num <= R_min:
        cnt += 1
print(cnt)

n, m = list(map(int, input().split()))
gate = []
for i in range(m):
    L, R = list(map(int, input().split()))
    gate.append((L, R))
L_max = 0
R_min = 10**6
for i in range(m):
    if gate[i][0] > L_max:
        L_max = gate[i][0]
for i in range(m):
    if gate[i][1] < R_min:
        R_min = gate[i][1]
ans = 0
for i in range(1, n + 1):
    if L_max <= i <= R_min:
        ans += 1
print(ans)

-N, M = list(map(int, input().split())) -w = [list(map(int, input().split())) for i in range(M)] +n, m = list(map(int, input().split())) +gate = [] +for i in range(m): +    L, R = list(map(int, input().split())) +    gate.append((L, R)) +L_max = 0 -L_max = 0 -cnt = 0 -for i in range(M): -    if w[i][1] <= R_min: -        R_min = w[i][1] -for i in range(M): -    if w[i][0] >= L_max: -        L_max = w[i][0] -for num in range(1, N + 1): -    if L_max <= num <= R_min: -        cnt += 1 -print(cnt) +for i in range(m): +    if gate[i][0] > L_max: +        L_max = gate[i][0] +for i in range(m): +    if gate[i][1] < R_min: +        R_min = gate[i][1] +ans = 0 +for i in range(1, n + 1): +    if L_max <= i <= R_min: +        ans += 1 +print(ans)