import  bisect
n=int(input())
a=[]
for _ in range(n):
    a.append(int(input()))

Ans=[-1]#0ではない

for i in range(n):
    #l=len(Ans)
    #for j in range(len(Ans)):
        #if i<j:
    #    if j!=l-1:
    #        if Ans[j]<a[i]<Ans[j+1]:
    #            Ans[j+1]=a[i]
                #print(*Ans)
    #    elif Ans[j]<a[i]:
    #        Ans.append(a[i])
    l=bisect.bisect_left(Ans,a[i])
    if l==len(Ans):
        Ans.append(a[i])
    else:
        Ans[l]=a[i]

#print(*Ans)

print(len(Ans)-1)

