import bisect

from collections import deque

N=int(eval(input()))

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

d=deque()



for i in range(N):

    p=bisect.bisect_left(d, a[i])

    #print(a[i], p, d)

    if p==0:

        d.appendleft(a[i])

    else:

        d[p-1]=a[i]

print((len(d)))
from collections import deque

import bisect

import sys



input = sys.stdin.readline

N = int(eval(input()))

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

A = A[::-1]



col = [A.pop()]

col = deque(col)



while A:

    a = A.pop()

    if a <= col[0]:

        col.appendleft(a)

    else:

        x = bisect.bisect_left(col, a)

        col[x - 1] = a



ans = len(col)

print(ans)

import bisect
from collections import deque

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

from collections import deque
import bisect
import sys

input = sys.stdin.readline
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A = A[::-1]
col = [A.pop()]
col = deque(col)
while A:
    a = A.pop()
    if a <= col[0]:
        col.appendleft(a)
    else:
        x = bisect.bisect_left(col, a)
        col[x - 1] = a
ans = len(col)
print(ans)

+from collections import deque -from collections import deque +import sys +input = sys.stdin.readline -a = [int(eval(input())) for _ in range(N)] -d = deque() -for i in range(N): -    p = bisect.bisect_left(d, a[i]) -    # print(a[i], p, d) -    if p == 0: -        d.appendleft(a[i]) +A = [int(eval(input())) for _ in range(N)] +A = A[::-1] +col = [A.pop()] +col = deque(col) +while A: +    a = A.pop() +    if a <= col[0]: +        col.appendleft(a) -        d[p - 1] = a[i] -print((len(d))) +        x = bisect.bisect_left(col, a) +        col[x - 1] = a +ans = len(col) +print(ans)