import sys
from bisect import bisect_left

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

for n in map(int, sys.stdin.readlines()):
    i = bisect_left(dp, n)
    dp[i] = n
    result = i if i > result else result

print(result+1)