from sys import stdin
readline = stdin.readline

n = int(readline())
a = [int(readline()) for _ in range(n)]

dp = [-float('inf')]

for ai in a:
    for i in range(1, len(dp)):
        if dp[i - 1] < ai and ai < dp[i]:
            dp[i] = ai
    if dp[-1] < ai:
        dp.append(ai)

print(len(dp) - 1)