import sys
from bisect import bisect_left

readline = sys.stdin.readline
N = int(readline())
a = [int(readline()) for _ in [0]*N]
inf = float("inf")
dp = [inf]*N

for num in a:
    dp[bisect_left(dp, num)] = num

for i, num in zip(range(N, 0, -1), dp[::-1]):
    if num < inf:
        print(i)
        break