from collections import deque

from bisect import bisect_left

inf = float('inf')





N = int(eval(input()))

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



color = deque()



for a in A:

    pos = bisect_left(color, a)

    if pos == 0:

        color.appendleft(a)

    else:

        color[pos-1] = a



ans = len(color)

print(ans)
from bisect import bisect

inf = float('inf')



# 広義単調増加

def LIS(arr):

    N = len(arr)

    dp = [inf] * N

    res = 0

    for a in arr:

        pos = bisect(dp,a)

        dp[pos] = a

        res = max(res, pos + 1)

    return res



N = int(eval(input()))

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



ans = LIS(A[::-1])

print(ans)
from collections import deque
from bisect import bisect_left

inf = float("inf")
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
color = deque()
for a in A:
    pos = bisect_left(color, a)
    if pos == 0:
        color.appendleft(a)
    else:
        color[pos - 1] = a
ans = len(color)
print(ans)

from bisect import bisect

inf = float("inf")
# 広義単調増加
def LIS(arr):
    N = len(arr)
    dp = [inf] * N
    res = 0
    for a in arr:
        pos = bisect(dp, a)
        dp[pos] = a
        res = max(res, pos + 1)
    return res


N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
ans = LIS(A[::-1])
print(ans)

-from collections import deque -from bisect import bisect_left +from bisect import bisect +# 広義単調増加 +def LIS(arr): +    N = len(arr) +    dp = [inf] * N +    res = 0 +    for a in arr: +        pos = bisect(dp, a) +        dp[pos] = a +        res = max(res, pos + 1) +    return res + + -color = deque() -for a in A: -    pos = bisect_left(color, a) -    if pos == 0: -        color.appendleft(a) -    else: -        color[pos - 1] = a -ans = len(color) +ans = LIS(A[::-1])