N = gets.chomp.to_i
AS = []
N.times { AS.push(gets.chomp.to_i) }

arr = [AS[0]]

1.upto(N - 1) do |i|
  if AS[i] <= arr[0]
    arr.unshift(AS[i])
    next
  end
  idx = arr.bsearch_index { |x| x > AS[i] }
  idx = arr.size if idx.nil?
  arr[idx - 1] = AS[i]
  p arr
end

puts arr.size
