import bisect

n = int(input())
A = [int(input()) for _ in range(n)]

que = [A[0]]

for a in A[1:]:
    if a > que[-1]:
        que.append(a)
    else:
        idx = bisect.bisect_left(que, a)
        que[idx] = a

print(len(que))
