import sys, bisect

def solve():
    A = list(map(int, sys.stdin.readlines()))
    n = A[0]
    A = A[1:]
    L = A[:1]
    for a_i in A[1:]:
        if a_i > L[-1]:
            L.append(a_i)
        else:
            j = bisect.bisect_left(L, a_i)
            L[j] = a_i
    print(len(L))

solve()