str1 = gets.split
N,M = str1[0].to_i, str1[1].to_i

l = 1
r = N

for x in 1..M
  str1 = gets.split
  li,ri = str1[0].to_i, str1[1].to_i
  if li > l
    l = li
  end
  if ri < r
    r = ri
  end
end

answer = r-l+1
if answer < 0
  answer = 0
end

puts answer