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

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

 

lm=0

rm=float('inf')

for i in range(m):

      lm=max(L[i][0],lm)

      rm=min(L[i][1],rm)

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

ml,mr=0,float('inf')

for i in range(m):

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

      ml=max(l,ml)

      mr=min(r,mr)

print((max(mr-ml+1,0)))
n, m = list(map(int, input().split()))
L = [list(map(int, input().split())) for _ in range(m)]
lm = 0
rm = float("inf")
for i in range(m):
    lm = max(L[i][0], lm)
    rm = min(L[i][1], rm)
print((max(0, rm - lm + 1)))

n, m = list(map(int, input().split()))
ml, mr = 0, float("inf")
for i in range(m):
    l, r = list(map(int, input().split()))
    ml = max(l, ml)
    mr = min(r, mr)
print((max(mr - ml + 1, 0)))

-L = [list(map(int, input().split())) for _ in range(m)] -lm = 0 -rm = float("inf") +ml, mr = 0, float("inf") -    lm = max(L[i][0], lm) -    rm = min(L[i][1], rm) -print((max(0, rm - lm + 1))) +    l, r = list(map(int, input().split())) +    ml = max(l, ml) +    mr = min(r, mr) +print((max(mr - ml + 1, 0)))