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

low = 1
high = n

for i in range(m):
    l, r = list(map(int, input().split()))
    low = max(low, l)
    high = min(high, r)

print(max(high - low + 1, 0))
 n, m = list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split m low = 1 low 1 high = n high n for i in range(m):
    l, r = list(map(int, input().split()))
    low = max(low, l)
    high = min(high, r) i range(m) range m l, r = list(map(int, input().split())) l list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split r low = max(low, l) low max(low, l) max low l high = min(high, r) high min(high, r) min high r print(max(high - low + 1, 0)) print max(high - low + 1, 0) max high - low + 1 high - low high low 1 0 high = n n high low = max(low, l) max(low, l) low l, r = list(map(int, input().split())) list(map(int, input().split())) l high = min(high, r) min(high, r) high r = list(map(int, input().split())) list(map(int, input().split())) r n, m = list(map(int, input().split())) list(map(int, input().split())) n low = 1 1 low m = list(map(int, input().split())) list(map(int, input().split())) m
n, m = list(map(int, input().split()))

low = 1
high = n

for i in range(m):
    l, r = list(map(int, input().split()))
    low = max(low, l)
    high = min(high, r)

print(max(high - low + 1, 0))

