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

l0,r0=1,n

for i in range(m):

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

  if l>r0 or r<l0:

    print((0))

    exit()

  else:

    l0=max(l0,l)

    r0=min(r0,r)

print((r0-l0+1))
n,m=list(map(int,input().split()))

l=[0 for _ in range(m)]

r=[0 for _ in range(m)]



for i in range(m):

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



lmax=max(l)

rmin=min(r)

if rmin>=lmax:

  print((rmin-lmax+1))

else:

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

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

-l0, r0 = 1, n +l = [0 for _ in range(m)] +r = [0 for _ in range(m)] -    l, r = list(map(int, input().split())) -    if l > r0 or r < l0: -        print((0)) -        exit() -    else: -        l0 = max(l0, l) -        r0 = min(r0, r) -print((r0 - l0 + 1)) +    l[i], r[i] = list(map(int, input().split())) +lmax = max(l) +rmin = min(r) +if rmin >= lmax: +    print((rmin - lmax + 1)) +else: +    print((0))