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

num_array = []
M.times{|n|
  l_num, r_num = gets.split.map(&:to_i)
  num_array << [*l_num..r_num]
}

target = num_array[0]

num_array.each do |n|
  add = target & n
  target = add
end

id_num_array = [*1..N]

puts((id_num_array & target).length)
