local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local function upper_bound(ary, x)
  local num = #ary
  if num == 0 then return 1 end
  if(x < ary[1]) then return 1 end
  if(ary[num] <= x) then return num + 1 end
  local min, max = 1, num
  while(1 < max - min) do
    local mid = mfl((min + max) / 2)
    if(ary[mid] <= x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
  a[i] = -a[i]
end
local t = {a[1]}
for i = 2, n do
  local pos = upper_bound(t, a[i])
  if i - 1 < pos then
    table.insert(t, a[i])
  else
    t[pos] = a[i]
  end
end
print(#t)
