import sys
from bisect import bisect_left

N = int(input())
inf = float("inf")
dp = [inf]*N

for n in map(int, sys.stdin.readlines()):
    dp[bisect_left(dp, n)] = n

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