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

