N = gets.chomp.to_i
a = []
N.times do
  a << gets.chomp.to_i
end

sorted = []
a.each do |n|
  # Early return
  if sorted.size == 0
    sorted.push(n)
    next
  end
  
  i = sorted.bsearch_index { |x| x >= n }
  if i == 0
    sorted.unshift(n)
  elsif i == nil
    sorted[sorted.size-1] = n
  else
    sorted[i-1] = n
  end
  
  # p "n: #{n}"
  # p "i: #{i}"
  # p sorted
end

p sorted.size