N,M = gets.split.map(&:to_i)
K = Array.new(N,0)
z = []
M.times do |i|
    l,r = gets.split.map(&:to_i)
    if z.empty? then
        z = [*l..r]
    else
        z = [*[z[0],l].max..[z[-1],r].min]
    end
end
puts z.length