import bisect
N = int(input())
A = [int(input()) for _ in range(N)]
L = [A[0]]
for i in range(1, N):
    if L[-1] < A[i]:
        L.append(A[i])
    else:
        L[bisect.bisect_left(L, A[i])] = A[i]
print(len(L))