n, m = gets.chomp.split(' ').map(&:to_i)

gates = []

m.times do |i|
  l, r = gets.chomp.split(' ').map(&:to_i)
  gates << [l,r]
end

cleard_num = 0

(1..n).each do |i|
  cleared = true
  gates.each do |l, r|
    unless l <= i and i <= r
      cleared = false
      break
    end
  end
  if cleared
    cleard_num = cleard_num + 1
  end
end

print "#{cleard_num}"