import bisect

N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

cnt = []   
for a in A:
    i = bisect.bisect_left(cnt, a)
    if i >= len(cnt):
        cnt.append(a)
    elif cnt[i] > a:
        cnt[i] = a

print(len(cnt))
