n = gets.to_i
a = (0..n).map {|i| i == 0 ? -1 : Float::INFINITY }
n.times do
  x  = gets.to_i
  i = (0..n).bsearch {|i| a[i] >= x } - 1
  a[i + 1] = x
end
n.downto(0) do |i|
  if a[i] != Float::INFINITY
    p i
    break
  end
end
