from bisect import bisect_left
n=int(input())
A=[int(input()) for _ in range(n)]

DP=[A[0]]
for i in range(1,n):
    num=A[i]
    if DP[-1]<num:
        DP.append(num)
    else:
        index=bisect_left(DP,num)
        DP[index]=num
print(len(DP))
