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()))

max_l = float("-inf")

min_r = float("inf")

for _ in range(m):

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

  max_l = max(max_l, l)

  min_r = min(min_r, r)

ans = min_r - max_l + 1

if ans > 0:

  print(ans)

else:

  print((0))
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()))
max_l = float("-inf")
min_r = float("inf")
for _ in range(m):
    l, r = list(map(int, input().split()))
    max_l = max(max_l, l)
    min_r = min(min_r, r)
ans = min_r - max_l + 1
if ans > 0:
    print(ans)
else:
    print((0))

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