import bisect
n = int(input())
A = [0]
for i in range(n):
    num  = int(input())
    if num>A[-1]:
        A.append(num)
    else:
        j = bisect.bisect_left(A, num)
        A[j] = num
print(len(A))