import sys
import bisect
readline = sys.stdin.readline

N = int(readline())
a = [int(readline())]
append = a.append
for _ in [None]*(N-1):
    n = int(readline())
    if a[-1] < n:
        append(n)
    else:
        a[bisect.bisect_left(a, n)] = n

print(len(a))