n, m = gets.split(" ").map(&:to_i)
gates = []
m.times do
  gates.push(gets.split(" ").map(&:to_i))
end
sum = 0
judge = true 
n.times do |index|
  gates.each do |gate|
    if gate[0] > (index + 1) || gate[1] < (index + 1)
      judge = false;
      break;
    end
  end
  if judge == true
    sum += 1
  end
  judge = true
end
puts sum