import bisect

from collections import deque



N = int(eval(input()))

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



LDS = deque()

LDS.append(A[0])



for i in range(1,N):

    if LDS[0] >= A[i]:

        LDS.appendleft(A[i])

    else:

        LDS[bisect.bisect_left(LDS,A[i])-1] = A[i]



print((len(LDS)))
from bisect import bisect_left, bisect_right



def LIS(arr):  #bisect.bisect_left

    n = len(arr)

    lis = [arr[0]]

    for a in arr:

        if a > lis[-1]:

            lis.append(a)

        else:

            lis[bisect_left(lis, a)] = a

    return len(lis)



import sys

input = sys.stdin.readline



N = int(eval(input()))



A = []

for i in range(N):

    A.append((-int(eval(input())), i))



print((LIS(A)))

import bisect
from collections import deque

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
LDS = deque()
LDS.append(A[0])
for i in range(1, N):
    if LDS[0] >= A[i]:
        LDS.appendleft(A[i])
    else:
        LDS[bisect.bisect_left(LDS, A[i]) - 1] = A[i]
print((len(LDS)))

from bisect import bisect_left, bisect_right


def LIS(arr):  # bisect.bisect_left
    n = len(arr)
    lis = [arr[0]]
    for a in arr:
        if a > lis[-1]:
            lis.append(a)
        else:
            lis[bisect_left(lis, a)] = a
    return len(lis)


import sys

input = sys.stdin.readline
N = int(eval(input()))
A = []
for i in range(N):
    A.append((-int(eval(input())), i))
print((LIS(A)))

-import bisect -from collections import deque +from bisect import bisect_left, bisect_right + +def LIS(arr):  # bisect.bisect_left +    n = len(arr) +    lis = [arr[0]] +    for a in arr: +        if a > lis[-1]: +            lis.append(a) +        else: +            lis[bisect_left(lis, a)] = a +    return len(lis) + + +import sys + +input = sys.stdin.readline -A = [int(eval(input())) for _ in range(N)] -LDS = deque() -LDS.append(A[0]) -for i in range(1, N): -    if LDS[0] >= A[i]: -        LDS.appendleft(A[i]) -    else: -        LDS[bisect.bisect_left(LDS, A[i]) - 1] = A[i] -print((len(LDS))) +A = [] +for i in range(N): +    A.append((-int(eval(input())), i)) +print((LIS(A)))