from bisect import bisect



N = int(eval(input()))

A = [int(eval(input())) for _ in range(N)]



INF = 10**10

dp = [-INF]

for a in A:

    if a <= -dp[-1]:

        dp.append(-a)

    else:

        i = bisect(dp, -a)

        dp[i] = -a

ans = len(dp) - 1

print(ans)

from bisect import bisect_left



N = int(eval(input()))

A = [int(eval(input())) for _ in range(N)]



# 解は最長非増加部分列の長さ

dp = [-1 for _ in range(N)]

for a in A:

    dp[bisect_left(dp, a) - 1] = a

ans = sum(x >= 0 for x in dp)



print(ans)

from bisect import bisect

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
INF = 10**10
dp = [-INF]
for a in A:
    if a <= -dp[-1]:
        dp.append(-a)
    else:
        i = bisect(dp, -a)
        dp[i] = -a
ans = len(dp) - 1
print(ans)

from bisect import bisect_left

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
# 解は最長非増加部分列の長さ
dp = [-1 for _ in range(N)]
for a in A:
    dp[bisect_left(dp, a) - 1] = a
ans = sum(x >= 0 for x in dp)
print(ans)

-from bisect import bisect +from bisect import bisect_left -INF = 10**10 -dp = [-INF] +# 解は最長非増加部分列の長さ +dp = [-1 for _ in range(N)] -    if a <= -dp[-1]: -        dp.append(-a) -    else: -        i = bisect(dp, -a) -        dp[i] = -a -ans = len(dp) - 1 +    dp[bisect_left(dp, a) - 1] = a +ans = sum(x >= 0 for x in dp)