a = []
l = []
gets.to_i.times do
  a << gets.to_i
end

l[0] = a[0]
length = 1

(1...a.size).each do |i|
  if l[length-1] < a[i]
    l[length] = a[i]
    length += 1
  else
    j = (0...l.size).bsearch { |k| a[i] <= l[k] }
    l[j] = a[i]
  end
end
puts length