from collections import deque

import bisect



N = int(eval(input()))



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



q = deque([A[0]])



for a in A[1:]:

    idx = bisect.bisect_left(q, a)

    if idx == 0:

        q.appendleft(a)

    else:

        q[idx-1] = a



print((len(q)))
import bisect



N = int(eval(input()))

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



def lis(S):

    from bisect import bisect_right

    L = [S[0]]



    for s in S[1:]:

        if s >= L[-1]:

            L.append(s)

        else:

            L[bisect_right(L, s)] = s

    return len(L)



print((lis(A[::-1])))
from collections import deque
import bisect

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

import bisect

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


def lis(S):
    from bisect import bisect_right

    L = [S[0]]
    for s in S[1:]:
        if s >= L[-1]:
            L.append(s)
        else:
            L[bisect_right(L, s)] = s
    return len(L)


print((lis(A[::-1])))

-from collections import deque -q = deque([A[0]]) -for a in A[1:]: -    idx = bisect.bisect_left(q, a) -    if idx == 0: -        q.appendleft(a) -    else: -        q[idx - 1] = a -print((len(q))) + + +def lis(S): +    from bisect import bisect_right + +    L = [S[0]] +    for s in S[1:]: +        if s >= L[-1]: +            L.append(s) +        else: +            L[bisect_right(L, s)] = s +    return len(L) + + +print((lis(A[::-1])))