n, m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(m)]
f_inf = float("inf")

max_l = 0
min_r = f_inf
for l, r in LR:
    max_l = max(max_l, l)
    min_r = min(min_r, r)

if min_r >= max_l:
    print(min_r - max_l + 1)
else:
    print(0) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split LR = [list(map(int, input().split())) for _ in range(m)] LR [list(map(int, input().split())) for _ in range(m)] f_inf = float("inf") f_inf float("inf") float "inf" max_l = 0 max_l 0 min_r = f_inf min_r f_inf for l, r in LR:
    max_l = max(max_l, l)
    min_r = min(min_r, r) l r LR max_l = max(max_l, l) max_l max(max_l, l) max max_l l min_r = min(min_r, r) min_r min(min_r, r) min min_r r if min_r >= max_l:
    print(min_r - max_l + 1)
else:
    print(0) min_r >= max_l min_r max_l print(min_r - max_l + 1) print min_r - max_l + 1 min_r - max_l min_r max_l 1 print(0) print 0 n, m = map(int, input().split()) map(int, input().split()) n LR = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] LR min_r = f_inf f_inf min_r max_l = max(max_l, l) max(max_l, l) max_l min_r = min(min_r, r) min(min_r, r) min_r m = map(int, input().split()) map(int, input().split()) m max_l = 0 0 max_l f_inf = float("inf") float("inf") f_inf
n, m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(m)]
f_inf = float("inf")

max_l = 0
min_r = f_inf
for l, r in LR:
    max_l = max(max_l, l)
    min_r = min(min_r, r)

if min_r >= max_l:
    print(min_r - max_l + 1)
else:
    print(0)