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

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

a=0

z=10**5

for i in range(m):

    a=max(a,l[i][0])

    z=min(z,l[i][1])

if a<=z:

    print((z-a+1))

else:

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

a=1

z=n

for _ in range(m):

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

    a=max(a,l)

    z=min(z,m)

print((max(0,z-a+1)))    
n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for _ in range(m)]
a = 0
z = 10**5
for i in range(m):
    a = max(a, l[i][0])
    z = min(z, l[i][1])
if a <= z:
    print((z - a + 1))
else:
    print((0))

n, m = list(map(int, input().split()))
a = 1
z = n
for _ in range(m):
    l, m = list(map(int, input().split()))
    a = max(a, l)
    z = min(z, m)
print((max(0, z - a + 1)))

-l = [list(map(int, input().split())) for _ in range(m)] -a = 0 -z = 10**5 -for i in range(m): -    a = max(a, l[i][0]) -    z = min(z, l[i][1]) -if a <= z: -    print((z - a + 1)) -else: -    print((0)) +a = 1 +z = n +for _ in range(m): +    l, m = list(map(int, input().split())) +    a = max(a, l) +    z = min(z, m) +print((max(0, z - a + 1)))