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



a=0

b=n

for i in range(m):

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

  a = max(a, l)

  b = min(b, r)

if b-a+1 >= 0:

  print((b-a+1))

else:

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

l = 1

r = 10**5

for _ in range(m):

  l_, r_ = list(map(int, input().split()))

  l = max(l, l_)

  r = min(r, r_)

  

if r>=l:

  print((r-l+1))

else:

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

n, m = list(map(int, input().split()))
l = 1
r = 10**5
for _ in range(m):
    l_, r_ = list(map(int, input().split()))
    l = max(l, l_)
    r = min(r, r_)
if r >= l:
    print((r - l + 1))
else:
    print((0))

-a = 0 -b = n -for i in range(m): -    l, r = list(map(int, input().split())) -    a = max(a, l) -    b = min(b, r) -if b - a + 1 >= 0: -    print((b - a + 1)) +l = 1 +r = 10**5 +for _ in range(m): +    l_, r_ = list(map(int, input().split())) +    l = max(l, l_) +    r = min(r, r_) +if r >= l: +    print((r - l + 1))