N = gets.to_i

ans = Array.new # 昇順

N.times do 
    a = gets.to_i

    if ans.size == 0
        ans.push(a)
        next
    end

    idx = ans.bsearch_index { |x| x >=  a }

    if idx == nil
        # a is the biggest
        ans[ans.size - 1] = a
    elsif idx == 0
        # a is the smallest
        ans.unshift(a)
    else
        ans[idx - 1] = a
    end
end

puts ans.size