import bisect as bi
import sys
N = int(sys.stdin.readline())
C = [int(sys.stdin.readline()) for i in range(N)]
inf = 10000000000
lis = [inf for i in range(N)]
for c_i in C:
    lis[bi.bisect_left(lis, c_i)] = c_i
print(bi.bisect_left(lis, inf))