N, M = [int(x) for x in input().split()]

L = []

R = []

for _ in range(M):

  l, r = [int(x) for x in input().split()]

  L.append(l)

  R.append(r)



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

print((ans if ans >= 0 else 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)



l = max(L)

r = min(R)

print((r-l+1 if r-l+1 > 0 else 0))
N, M = [int(x) for x in input().split()]
L = []
R = []
for _ in range(M):
    l, r = [int(x) for x in input().split()]
    L.append(l)
    R.append(r)
ans = min(R) - max(L) + 1
print((ans if ans >= 0 else 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)
l = max(L)
r = min(R)
print((r - l + 1 if r - l + 1 > 0 else 0))

-N, M = [int(x) for x in input().split()] +N, M = list(map(int, input().split())) -    l, r = [int(x) for x in input().split()] +    l, r = list(map(int, input().split())) -ans = min(R) - max(L) + 1 -print((ans if ans >= 0 else 0)) +l = max(L) +r = min(R) +print((r - l + 1 if r - l + 1 > 0 else 0))