nm = STDIN.gets.chomp.split(' ').map(&:to_i)

inputs = []

nm[1].times do
  inputs << STDIN.gets.chomp.split(' ').map(&:to_i)
end

count = 0
(1..nm[0]).each do |i|
  flag = true
  inputs.each do |array|
    unless array[0] <= i && i <= array[1]
      flag = false
      break
    end
  end
  count += 1 if flag
end

puts count