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

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



mi = 0

ma = n

for i in range(m):

  mi = max(mi, lr[i][0])

  ma = min(ma, lr[i][1])

  

  

if ma-mi>=0:

  print((ma-mi+1))

else:

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

lb=0

ub=n

for i in range(m):

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

  lb=max(lb,l)

  ub=min(ub,r)

  

if ub>=lb:

  print((ub-lb+1))

else:

  print((0))
n, m = list(map(int, input().split()))
lr = [list(map(int, input().split())) for i in range(m)]
mi = 0
ma = n
for i in range(m):
    mi = max(mi, lr[i][0])
    ma = min(ma, lr[i][1])
if ma - mi >= 0:
    print((ma - mi + 1))
else:
    print((0))

n, m = list(map(int, input().split()))
lb = 0
ub = n
for i in range(m):
    l, r = list(map(int, input().split()))
    lb = max(lb, l)
    ub = min(ub, r)
if ub >= lb:
    print((ub - lb + 1))
else:
    print((0))

-lr = [list(map(int, input().split())) for i in range(m)] -mi = 0 -ma = n +lb = 0 +ub = n -    mi = max(mi, lr[i][0]) -    ma = min(ma, lr[i][1]) -if ma - mi >= 0: -    print((ma - mi + 1)) +    l, r = list(map(int, input().split())) +    lb = max(lb, l) +    ub = min(ub, r) +if ub >= lb: +    print((ub - lb + 1))