ary=Array.new
n,m=$stdin.gets.split(/\s+/).collect{|e| e.to_i}
n.times do |i|
  ary << (i+1)
end
m.times do |i|
  l,r=$stdin.gets.split(/\s+/).collect{|e| e.to_i}
  ary.size.times do |i|
    tmp=ary.shift
    ary.push(tmp) if tmp >= l && tmp <= r
  end
end
puts "#{ary.size}"