from sys import stdin
from bisect import bisect_left, bisect_right
readline = stdin.readline

dp = [-float('inf')]

for ai in (int(readline()) for _ in range(int(readline()))):
    if dp[-1] < ai:dp.append(ai)
    for i in range(bisect_right(dp, ai), bisect_left(dp, ai) + 1):dp[i] = ai
print(len(dp) - 1)