local function upper_bound(key,ary)
    local n=#ary
    if n==0 then
        return 1 
    end
    if key<ary[1] then
        return 1
    end
    if key>=ary[n] then
        return n+1
    end
    local min,max=1,n
    while 1<max-min do
        local mid=(min+max)//2
        if key>=ary[mid] 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")
end

local INF=math.maxinteger
local dp={}
for i=1,n do
    dp[i]=INF
end

local len=0
for i=n,1,-1 do
    local k=upper_bound(a[i],dp)
    dp[k]=a[i]
    len=math.max(k,len)
end
print(len)