def add_color_array(a)
  if C.empty? then
    C << a
  elsif C[0] >= a then
    C.unshift(a)
  elsif C[-1] < a then
    C[-1] = a
  else
    C[C.bsearch_index{|b| b >= a} - 1] = a
  end
end

C = []
N = gets.to_i
N.times{
  add_color_array(gets.to_i)
}

puts C.size
