n = gets.chomp.to_i
stack = []
for i in 1..n do 
    a = gets.chomp.to_i
    # print a,stack,"\n"
    if stack.empty?
        stack.push(a)
        next
    end
    head = 0
    tail = (stack.size) -1
    mid = (head+tail)/2
    
    if stack[tail] >= a
        stack.push(a)
        next
    end

    while head < tail
        if stack[mid] >= a
            head = mid+1
        else
            tail = mid
        end
        mid = (head+tail)/2
    end

    stack[mid] = a
end


p stack.size