n,m = gets.split(' ').map(&:to_i)
can_pass = [] 
existed = []
(m).times do |a|
    l,r = gets.split(' ').map(&:to_i)
    if a == 0
        existed = (l..r).to_a
    else
        can_pass = (l..r).to_a
        existed = can_pass & existed
    end
end
puts existed.length