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

L = []

R = []

for _ in range(M):

    tmp1,tmp2 = list(map(int,input().split()))

    L.append(tmp1)

    R.append(tmp2)



max_L = L[0]

min_R = R[0]

for i in range(1,M):

    max_L = max(max_L, L[i])

    min_R = min(min_R, R[i])



if min_R >= max_L:

    res = min_R - max_L + 1

else:

    res = 0

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

max_l = 0

min_r = 10**5

for i in range(m):

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

  if l > max_l:

    max_l = l

  if r < min_r:

    min_r = r

max_l = min(n+1, max_l)

min_r = min(n+1, min_r)

res = min_r - max_l + 1

if res<0:

  res = 0

print(res)
N, M = list(map(int, input().split()))
L = []
R = []
for _ in range(M):
    tmp1, tmp2 = list(map(int, input().split()))
    L.append(tmp1)
    R.append(tmp2)
max_L = L[0]
min_R = R[0]
for i in range(1, M):
    max_L = max(max_L, L[i])
    min_R = min(min_R, R[i])
if min_R >= max_L:
    res = min_R - max_L + 1
else:
    res = 0
print(res)

n, m = list(map(int, input().split()))
max_l = 0
min_r = 10**5
for i in range(m):
    l, r = list(map(int, input().split()))
    if l > max_l:
        max_l = l
    if r < min_r:
        min_r = r
max_l = min(n + 1, max_l)
min_r = min(n + 1, min_r)
res = min_r - max_l + 1
if res < 0:
    res = 0
print(res)

-N, M = list(map(int, input().split())) -L = [] -R = [] -for _ in range(M): -    tmp1, tmp2 = list(map(int, input().split())) -    L.append(tmp1) -    R.append(tmp2) -max_L = L[0] -min_R = R[0] -for i in range(1, M): -    max_L = max(max_L, L[i]) -    min_R = min(min_R, R[i]) -if min_R >= max_L: -    res = min_R - max_L + 1 -else: +n, m = list(map(int, input().split())) +max_l = 0 +min_r = 10**5 +for i in range(m): +    l, r = list(map(int, input().split())) +    if l > max_l: +        max_l = l +    if r < min_r: +        min_r = r +max_l = min(n + 1, max_l) +min_r = min(n + 1, min_r) +res = min_r - max_l + 1 +if res < 0: