from bisect import bisect_left
n=int(input())
a=[int(input()) for _ in range(n)]
dp=[float('inf') for _ in range(n)]
l=[]
l.append(a[0])
dp[0]=a[0]
for i in a[1:]:
    if l[-1]<i:
        l.append(i)
        dp[len(l)-1]=i
    else:
        x=bisect_left(l,i)
        dp[x]=i
        l[x]=i
print(len(l))
