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

maxl,minr=0,n

for i in range(m):

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

    maxl=max(maxl,l)

    minr=min(minr,r)

print((max(0,minr-maxl+1)))
n,m=list(map(int,input().split()))

card=[0]*(n+1)

for _ in range(m):

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

    card[l-1]+=1

    card[r]-=1

for i in range(1,n+1):

    card[i]+=card[i-1]

print((card.count(m)))
n, m = list(map(int, input().split()))
maxl, minr = 0, n
for i in range(m):
    l, r = list(map(int, input().split()))
    maxl = max(maxl, l)
    minr = min(minr, r)
print((max(0, minr - maxl + 1)))

n, m = list(map(int, input().split()))
card = [0] * (n + 1)
for _ in range(m):
    l, r = list(map(int, input().split()))
    card[l - 1] += 1
    card[r] -= 1
for i in range(1, n + 1):
    card[i] += card[i - 1]
print((card.count(m)))

-maxl, minr = 0, n -for i in range(m): +card = [0] * (n + 1) +for _ in range(m): -    maxl = max(maxl, l) -    minr = min(minr, r) -print((max(0, minr - maxl + 1))) +    card[l - 1] += 1 +    card[r] -= 1 +for i in range(1, n + 1): +    card[i] += card[i - 1] +print((card.count(m)))