N, M = gets.split.map(&:to_i)

max_l = 0
min_r = 10**6
M.times do
  l, r = gets.split.map(&:to_i)
  max_l = [max_l, l].max
  min_r = [min_r, r].min
end

if min_r < max_l
  puts 0
else
  puts min_r - max_l + 1
end
