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

lr = [0, 10**6]

for _ in range(m):

  t = sorted(list(map(int, input().split())))

  lr[0] = max(lr[0], t[0])

  lr[1] = min(lr[1], t[1])



ans = lr[1] - lr[0] + 1

if ans < 0:

  print((0))

else:

  print(ans)
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 = min(R)-max(L)+1

if ans < 0:

  print((0))

else:

  print(ans)

  
n, m = list(map(int, input().split()))
lr = [0, 10**6]
for _ in range(m):
    t = sorted(list(map(int, input().split())))
    lr[0] = max(lr[0], t[0])
    lr[1] = min(lr[1], t[1])
ans = lr[1] - lr[0] + 1
if ans < 0:
    print((0))
else:
    print(ans)

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 = min(R) - max(L) + 1
if ans < 0:
    print((0))
else:
    print(ans)

-n, m = list(map(int, input().split())) -lr = [0, 10**6] -for _ in range(m): -    t = sorted(list(map(int, input().split()))) -    lr[0] = max(lr[0], t[0]) -    lr[1] = min(lr[1], t[1]) -ans = lr[1] - lr[0] + 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 = min(R) - max(L) + 1