line = readlines.map(&:to_i)

N = line[0]

ans = []
for i in 1..N do
  if ans == [] then
    ans.unshift(line[i])
  else
    found = false
    j = (ans.length - 1) / 2
    min = -1
    max = ans.length - 1
    while found == false do
      if ans[j] < line[i] then   #can be colored j
        min = j
        j = (max + j + 1) / 2
      else
        max = j - 1
        j = (min + j) / 2
      end
      if min == max then
        found = true
      end
    end
    if min == -1 then
      ans.unshift(line[i])
    else
      ans[min] = line[i]
    end
  end
end
        
print ans.length