def ltor(lr)
    [*lr[0]..lr[1]]
end

def cc
	n,m = gets.chomp.split(/\s/).map{|x| x.to_i}

    arr = ltor(gets.chomp.split(/\s/).map{|x| x.to_i})
    lr = []
    for i in 2..m
        arr &= ltor(gets.chomp.split(/\s/).map{|x| x.to_i})
    end

    puts arr.length
end

cc
