N = gets.chomp.to_i
A = []
N.times do
  A << gets.chomp.to_i
end
# S = gets.chomp.chars

sorted = []
A.each do |i|
  if sorted.size == 0
    sorted << i
    next
  end
  
  r = sorted.bsearch_index { |x| x >= i }
  if r.nil?  # i is larger than all value
    sorted[sorted.size-1] = i
  elsif r == 0  # i is equal or smaller than first value
    sorted.unshift(i)
  else 
    sorted[r-1] = i
  end
end

p sorted.size