n = gets.chomp.to_i
stack = []
# min = Float::INFINITY
for i in 1..n do 
    a = gets.chomp.to_i
    # if min >= a
    #     stack.push(a)
    #     min = a
    # else
        head = 0
        tail = (stack.size) -1
        mid = (head+tail)/2
        
        while head < tail
            if stack[mid] > a
                head = mid+1
            else
                tail = mid-1
            end
            mid = (head+tail)/2
        end
        stack[mid] = a
    # end
end

p stack.size