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

L = []

R = []

for _ in range(m):

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

  L.append(l)

  R.append(r)

  

ans = max(0, min(R) - max(L) + 1)



print(ans)



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

LR = [list(map(int, input().split())) for _ in range(m)]



l = 1

r = n



for i, j in LR:

  l = max(l, i)

  r = min(r, j)

  

print((max(0, r - l + 1)))
n, m = list(map(int, input().split()))
L = []
R = []
for _ in range(m):
    l, r = list(map(int, input().split()))
    L.append(l)
    R.append(r)
ans = max(0, min(R) - max(L) + 1)
print(ans)

n, m = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(m)]
l = 1
r = n
for i, j in LR:
    l = max(l, i)
    r = min(r, j)
print((max(0, r - l + 1)))

-L = [] -R = [] -for _ in range(m): -    l, r = list(map(int, input().split())) -    L.append(l) -    R.append(r) -ans = max(0, min(R) - max(L) + 1) -print(ans) +LR = [list(map(int, input().split())) for _ in range(m)] +l = 1 +r = n +for i, j in LR: +    l = max(l, i) +    r = min(r, j) +print((max(0, r - l + 1)))