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

l_max = 1
r_min = N
for _ in range(M):
    l, r = map(int, input().split())
    l_max = max(l_max, l)
    r_min = min(r_min, r)

if r_min < l_max:
    print(0)
else:
    print(r_min-l_max+1) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M l_max = 1 l_max 1 r_min = N r_min N for _ in range(M):
    l, r = map(int, input().split())
    l_max = max(l_max, l)
    r_min = min(r_min, r) _ range(M) range M l, r = map(int, input().split()) l map(int, input().split()) map int input().split() ().split () input split r l_max = max(l_max, l) l_max max(l_max, l) max l_max l r_min = min(r_min, r) r_min min(r_min, r) min r_min r if r_min < l_max:
    print(0)
else:
    print(r_min-l_max+1) r_min < l_max r_min l_max print(0) print 0 print(r_min-l_max+1) print r_min-l_max+1 r_min-l_max r_min l_max 1 r_min = N N r_min l_max = 1 1 l_max r = map(int, input().split()) map(int, input().split()) r N, M = map(int, input().split()) map(int, input().split()) N l, r = map(int, input().split()) map(int, input().split()) l M = map(int, input().split()) map(int, input().split()) M r_min = min(r_min, r) min(r_min, r) r_min l_max = max(l_max, l) max(l_max, l) l_max
N, M = map(int, input().split())

l_max = 1
r_min = N
for _ in range(M):
    l, r = map(int, input().split())
    l_max = max(l_max, l)
    r_min = min(r_min, r)

if r_min < l_max:
    print(0)
else:
    print(r_min-l_max+1)