



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

gates = []

for i in range(m):

    gates.append(list(map(int,input().split(" "))))



result = [1, n]



for card in gates:

    if result[0] < card[0]:

        result[0] = card[0]

    if result[1] > card[1]:

        result[1] = card[1]



tmp = result[1] - result[0] + 1 

if tmp >= 0:

    print(tmp)

else:

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



lr = []



ming = 0

maxg = 10 **6



for i in range(m):

    a,b = list(map(int,input().split(" ")))

    lr.append((a,b))



for i in lr:

    if i[0] > ming:

        ming = i[0]

    if i[1] < maxg:

        maxg = i[1]



print((max([0, maxg - ming + 1])))
n, m = list(map(int, input().split(" ")))
gates = []
for i in range(m):
    gates.append(list(map(int, input().split(" "))))
result = [1, n]
for card in gates:
    if result[0] < card[0]:
        result[0] = card[0]
    if result[1] > card[1]:
        result[1] = card[1]
tmp = result[1] - result[0] + 1
if tmp >= 0:
    print(tmp)
else:
    print((0))

n, m = list(map(int, input().split(" ")))
lr = []
ming = 0
maxg = 10**6
for i in range(m):
    a, b = list(map(int, input().split(" ")))
    lr.append((a, b))
for i in lr:
    if i[0] > ming:
        ming = i[0]
    if i[1] < maxg:
        maxg = i[1]
print((max([0, maxg - ming + 1])))

-gates = [] +lr = [] +ming = 0 +maxg = 10**6 -    gates.append(list(map(int, input().split(" ")))) -result = [1, n] -for card in gates: -    if result[0] < card[0]: -        result[0] = card[0] -    if result[1] > card[1]: -        result[1] = card[1] -tmp = result[1] - result[0] + 1 -if tmp >= 0: -    print(tmp) -else: -    print((0)) +    a, b = list(map(int, input().split(" "))) +    lr.append((a, b)) +for i in lr: +    if i[0] > ming: +        ming = i[0] +    if i[1] < maxg: +        maxg = i[1] +print((max([0, maxg - ming + 1])))