import bisect
N=int(input())

L=[]
for i in range(N):
    n=int(input())
    L.append(n)
    
dp=[10**20 for i in range(N)]
dp[0]=L[0]
for i in range(1,len(L)):
    dp[bisect.bisect_left(dp,L[i])]=L[i]
#print(dp)
cnt=0
for i in range(len(L)):
    if dp[i]<10**20:
        cnt+=1
    else:
        break
print(cnt)
