from collections import deque

from bisect import bisect_left



N = int(eval(input()))

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



t = deque([A[0]])

for a in A[1:]:

    if a <= t[0]:

        t.appendleft(a)

    else:

        t[bisect_left(t, a) - 1] = a

print((len(t)))

from bisect import bisect_right



N = int(eval(input()))

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



t = [-A[0]]

for a in A[1:]:

    if a <= -t[-1]:

        t.append(-a)

    else:

        t[bisect_right(t, -a)] = -a

print((len(t)))

from collections import deque
from bisect import bisect_left

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
t = deque([A[0]])
for a in A[1:]:
    if a <= t[0]:
        t.appendleft(a)
    else:
        t[bisect_left(t, a) - 1] = a
print((len(t)))

from bisect import bisect_right

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
t = [-A[0]]
for a in A[1:]:
    if a <= -t[-1]:
        t.append(-a)
    else:
        t[bisect_right(t, -a)] = -a
print((len(t)))

-from collections import deque -from bisect import bisect_left +from bisect import bisect_right -t = deque([A[0]]) +t = [-A[0]] -    if a <= t[0]: -        t.appendleft(a) +    if a <= -t[-1]: +        t.append(-a) -        t[bisect_left(t, a) - 1] = a +        t[bisect_right(t, -a)] = -a