from bisect import bisect_left, bisect_right



N = int(eval(input()))

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





dp = [float('inf')] * (N+1)

for A in reversed(As):

    i = bisect_right(dp, A)

    dp[i] = A



print((dp.index(float('inf'))))

from bisect import bisect_left, bisect_right

import sys

input = sys.stdin.readline



INF = float('inf')



N = int(eval(input()))

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



def getLenLNDS(As):

    dp = [-INF]

    for A in As:

        if dp[-1] <= A:

            dp.append(A)

        else:

            i = bisect_right(dp, A)

            dp[i] = A

    return len(dp)-1



ans = getLenLNDS(As)



print(ans)

from bisect import bisect_left, bisect_right

N = int(eval(input()))
As = [int(eval(input())) for _ in range(N)]
dp = [float("inf")] * (N + 1)
for A in reversed(As):
    i = bisect_right(dp, A)
    dp[i] = A
print((dp.index(float("inf"))))

from bisect import bisect_left, bisect_right
import sys

input = sys.stdin.readline
INF = float("inf")
N = int(eval(input()))
As = [-int(eval(input())) for _ in range(N)]


def getLenLNDS(As):
    dp = [-INF]
    for A in As:
        if dp[-1] <= A:
            dp.append(A)
        else:
            i = bisect_right(dp, A)
            dp[i] = A
    return len(dp) - 1


ans = getLenLNDS(As)
print(ans)

+import sys +input = sys.stdin.readline +INF = float("inf") -As = [int(eval(input())) for _ in range(N)] -dp = [float("inf")] * (N + 1) -for A in reversed(As): -    i = bisect_right(dp, A) -    dp[i] = A -print((dp.index(float("inf")))) +As = [-int(eval(input())) for _ in range(N)] + + +def getLenLNDS(As): +    dp = [-INF] +    for A in As: +        if dp[-1] <= A: +            dp.append(A) +        else: +            i = bisect_right(dp, A) +            dp[i] = A +    return len(dp) - 1 + + +ans = getLenLNDS(As) +print(ans)