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

9a7a2669230786b16285de5fe75332100e9c2baf
<mask token>

<mask token>
for _ in range(M):
    l, r = map(int, input().split())
    L = max(l, L)
    R = min(r, R)
print(len(range(L, R + 1)))

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