def sequence_decomposing(arr)
  seq_last_nums = [arr.shift]

  arr.each do |a|
    j = seq_last_nums.bsearch_index { |x| x >= a }

    if j.nil?
      seq_last_nums[-1] = a
    elsif j == 0
      seq_last_nums.unshift(a)
    else
      seq_last_nums[j - 1] = a
    end
  end

  seq_last_nums.size
end

n = gets.to_i
arr = []
n.times{ arr << gets.to_i }

puts sequence_decomposing(arr)
