from collections import deque

from bisect import bisect_left



n = int(eval(input()))

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



dq = deque()

for e in a:

    i = bisect_left(dq, e)

    if i == 0:

        dq.appendleft(e)

    else:

        dq[i-1] = e



ans = len(dq)

print(ans)

from bisect import bisect_right



n = int(eval(input()))

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



li = list()

for e in a:

    i = bisect_right(li, e)

    if i == len(li):

        li.append(e)

    else:

        li[i] = e



ans = len(li)

print(ans)

from collections import deque
from bisect import bisect_left

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
dq = deque()
for e in a:
    i = bisect_left(dq, e)
    if i == 0:
        dq.appendleft(e)
    else:
        dq[i - 1] = e
ans = len(dq)
print(ans)

from bisect import bisect_right

n = int(eval(input()))
a = [-int(eval(input())) for _ in range(n)]
li = list()
for e in a:
    i = bisect_right(li, e)
    if i == len(li):
        li.append(e)
    else:
        li[i] = e
ans = len(li)
print(ans)

-from collections import deque -from bisect import bisect_left +from bisect import bisect_right -a = [int(eval(input())) for _ in range(n)] -dq = deque() +a = [-int(eval(input())) for _ in range(n)] +li = list() -    i = bisect_left(dq, e) -    if i == 0: -        dq.appendleft(e) +    i = bisect_right(li, e) +    if i == len(li): +        li.append(e) -        dq[i - 1] = e -ans = len(dq) +        li[i] = e +ans = len(li)