def compare_interval(a_l,a_r,b_l,b_r)
  if a_l <= b_l
    if a_r < b_l
      return false
    else
      return [b_l,[a_r,b_r].min]
    end
  else
    if a_l > b_r
      return false
    else
      return [a_r,[b_l,a_l].min]
    end
  end
end
n,m = gets.chomp.split(' ').map(&:to_i)
flag = "ok"
former = [1,n]
m.times do
  l,r = gets.chomp.split(' ').map(&:to_i)
  if compare_interval(former[0],former[1],l,r)
    former = compare_interval(former[0],former[1],l,r)
  else
    flag = "ng"
    break
  end
end
if flag == "ok"
  puts former[1] - former[0] + 1
else
  puts 0
end
