from bisect import bisect_right



N = int(eval(input()))

S = [1]



for _ in range(N):

    a = int(eval(input()))

    a *= -1

    i = bisect_right(S, a)



    if i == len(S):

        S.append(a)

    else:

        S[i] = a



print((len(S)))
from bisect import bisect_right

import sys

input = sys.stdin.buffer.readline



N = int(eval(input()))

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



dp = [10**10] * N



for a in A:

    a = -a

    dp[bisect_right(dp, a)] = a



ans = N - dp.count(10**10)

print(ans)

from bisect import bisect_right

N = int(eval(input()))
S = [1]
for _ in range(N):
    a = int(eval(input()))
    a *= -1
    i = bisect_right(S, a)
    if i == len(S):
        S.append(a)
    else:
        S[i] = a
print((len(S)))

from bisect import bisect_right
import sys

input = sys.stdin.buffer.readline
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
dp = [10**10] * N
for a in A:
    a = -a
    dp[bisect_right(dp, a)] = a
ans = N - dp.count(10**10)
print(ans)

+import sys +input = sys.stdin.buffer.readline -S = [1] -for _ in range(N): -    a = int(eval(input())) -    a *= -1 -    i = bisect_right(S, a) -    if i == len(S): -        S.append(a) -    else: -        S[i] = a -print((len(S))) +A = [int(eval(input())) for _ in range(N)] +dp = [10**10] * N +for a in A: +    a = -a +    dp[bisect_right(dp, a)] = a +ans = N - dp.count(10**10) +print(ans)