from bisect import bisect_left

n = int(input())
dp = [int(1e9) + 1] * n
eol = 0

for _ in range(n):
    a = int(input())
    if dp[eol] < a:
        eol += 1
        dp[eol] = a
    else:
        dp[bisect_left(dp, a, hi=eol)] = a

print(eol + 1)