from bisect import bisect_right,bisect_left

n=int(eval(input()))

a=[int(eval(input())) for _ in range(n)]

INF=float('INF')

l=[INF]*n

for i in a[::-1]:

    l[bisect_right(l,i)]=i

print((bisect_left(l,INF)))
from bisect import bisect_left,bisect_right

n=int(eval(input()))

INF=float('inf')

l=[INF]*n

a=[int(eval(input())) for _ in range(n)]

for i in a[::-1]:

    l[bisect_right(l,i)]=i

print((bisect_left(l,INF)))
from bisect import bisect_right, bisect_left

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
INF = float("INF")
l = [INF] * n
for i in a[::-1]:
    l[bisect_right(l, i)] = i
print((bisect_left(l, INF)))

from bisect import bisect_left, bisect_right

n = int(eval(input()))
INF = float("inf")
l = [INF] * n
a = [int(eval(input())) for _ in range(n)]
for i in a[::-1]:
    l[bisect_right(l, i)] = i
print((bisect_left(l, INF)))

-from bisect import bisect_right, bisect_left +from bisect import bisect_left, bisect_right +INF = float("inf") +l = [INF] * n -INF = float("INF") -l = [INF] * n