n = int(input())
seq=[]
for i in range(n):
    seq.append(int(input()))

import bisect

Lis = [seq[0]]
for i in range(1,n):
    if seq[i] > Lis[-1]:
        Lis.append(seq[i])
    else:
        Lis[bisect.bisect_left(Lis,seq[i])] = seq[i]

print(len(Lis))
        
