N,*as=$<.read.split.map(&:to_i)

arr = [10**9+1]

as.each do |a|
  idx = arr.bsearch_index {|n| a <= n}
  if idx
    if idx-1 < 0
      arr.unshift a
    else
      arr[idx-1] = a
    end
  else
    arr.unshift a
  end
end

ret = arr.length - 1
puts ret
