n, m = [int(i) for i in input().split()]



l = []

r = []

for _ in range(m):

  l_tmp, r_tmp = [int(i) for i in input().split()]

  l.append(l_tmp)

  r.append(r_tmp)

  

l_max = max(l)

r_min = min(r)



ans = r_min - l_max + 1



if ans > 0:

  print(ans)

else:

  print((0))

n, m = [int(i) for i in input().split()]



l_max = 0

r_min = float('inf')

for _ in range(m):

  l, r = [int(i) for i in input().split()]

  if l > l_max:

    l_max = l

  if r < r_min:

    r_min = r



ans = r_min - l_max + 1



if ans > 0:

  print(ans)

else:

  print((0))

n, m = [int(i) for i in input().split()]
l = []
r = []
for _ in range(m):
    l_tmp, r_tmp = [int(i) for i in input().split()]
    l.append(l_tmp)
    r.append(r_tmp)
l_max = max(l)
r_min = min(r)
ans = r_min - l_max + 1
if ans > 0:
    print(ans)
else:
    print((0))

n, m = [int(i) for i in input().split()]
l_max = 0
r_min = float("inf")
for _ in range(m):
    l, r = [int(i) for i in input().split()]
    if l > l_max:
        l_max = l
    if r < r_min:
        r_min = r
ans = r_min - l_max + 1
if ans > 0:
    print(ans)
else:
    print((0))

-l = [] -r = [] +l_max = 0 +r_min = float("inf") -    l_tmp, r_tmp = [int(i) for i in input().split()] -    l.append(l_tmp) -    r.append(r_tmp) -l_max = max(l) -r_min = min(r) +    l, r = [int(i) for i in input().split()] +    if l > l_max: +        l_max = l +    if r < r_min: +        r_min = r