import os, sys, re, math



N, M = [int(s) for s in input().split(' ')]



min_idx = 1

max_idx = 1e+5



for _ in range(M):

    l,r = [int(s) for s in input().split(' ')]

    min_idx = max(min_idx, l)

    max_idx = min(max_idx, r)

if max_idx >= min_idx:

    print((min(N, int(max_idx - min_idx + 1))))

else:

    print((0))

import os, sys, re, math



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



L = 1

R = N



for _ in range(M):

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

	L = max(L,l)

	R = min(R,r)



ret = max(0, R-L+1)

print(ret)
import os, sys, re, math

N, M = [int(s) for s in input().split(" ")]
min_idx = 1
max_idx = 1e5
for _ in range(M):
    l, r = [int(s) for s in input().split(" ")]
    min_idx = max(min_idx, l)
    max_idx = min(max_idx, r)
if max_idx >= min_idx:
    print((min(N, int(max_idx - min_idx + 1))))
else:
    print((0))

import os, sys, re, math

N, M = list(map(int, input().split(" ")))
L = 1
R = N
for _ in range(M):
    l, r = list(map(int, input().split(" ")))
    L = max(L, l)
    R = min(R, r)
ret = max(0, R - L + 1)
print(ret)

-N, M = [int(s) for s in input().split(" ")] -min_idx = 1 -max_idx = 1e5 +N, M = list(map(int, input().split(" "))) +L = 1 +R = N -    l, r = [int(s) for s in input().split(" ")] -    min_idx = max(min_idx, l) -    max_idx = min(max_idx, r) -if max_idx >= min_idx: -    print((min(N, int(max_idx - min_idx + 1)))) -else: -    print((0)) +    l, r = list(map(int, input().split(" "))) +    L = max(L, l) +    R = min(R, r) +ret = max(0, R - L + 1) +print(ret)