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))
from sys import stdin

from bisect import bisect_left

readline = stdin.readline





dp = [-float('inf')]

n = int(readline())

a = (int(readline()) for _ in range(n))

for ai in a:

    if dp[-1] < ai:

        dp.append(ai)

    else:

        dp[bisect_left(dp, ai)] = ai

print((len(dp) - 1))
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))

from sys import stdin
from bisect import bisect_left

readline = stdin.readline
dp = [-float("inf")]
n = int(readline())
a = (int(readline()) for _ in range(n))
for ai in a:
    if dp[-1] < ai:
        dp.append(ai)
    else:
        dp[bisect_left(dp, ai)] = ai
print((len(dp) - 1))

-from bisect import bisect_left, bisect_right +from bisect import bisect_left -for ai in (int(readline()) for _ in range(int(readline()))): +n = int(readline()) +a = (int(readline()) for _ in range(n)) +for ai in a: -    for i in range(bisect_right(dp, ai), bisect_left(dp, ai) + 1): -        dp[i] = ai +    else: +        dp[bisect_left(dp, ai)] = ai