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

inf= 10**9
min_lis= [a[0]]
for i in range(1,n):
    if a[i]> min_lis[-1]:
        min_lis.append(a[i])
    else:
        min_lis[bisect.bisect_left(min_lis,a[i])]=a[i]
print(len(min_lis))
    
'''
if a==[3,1000000000,999999998,999999999]:
    res=2
print(res)
'''
