N = gets.chomp.to_i
a = Array.new(1,10**9+1)
color = 0
left = 0
right = 0
center = 0
for i in 1..N do
    x = gets.chomp.to_i
    if x <= a[color]
        a.push(x)
        color += 1
    else
        left = 0
        right = color
        while left != right
            center = (left+right)/2
            if a[center] < x
                right = center
            elsif
                left = center+1
            end
        end
        a[left] = x
    end
end
puts color