input = gets.chomp.split
n = input[0].to_i
m = input[1].to_i

list = []
m.times do
  lr = gets.chomp.split.map!(&:to_i)
  list << lr
end
# puts "#{list}"

min, max = 0, n
for i in 0..(list.count - 1) do
  if list[i][0] > min
    min = list[i][0]
  end
  if list[i][1] < max
    max = list[i][1]
  end
end
# puts max, min

if min > max
  puts 0
else
  puts max - min + 1
end
