import sys

input = sys.stdin.readline

from collections import deque

import bisect



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])

    if p==0:

        d.appendleft(A[i])

    else:

        d[p-1] = A[i]

ans = len(d)

print(ans)

import sys

input = sys.stdin.readline

from collections import deque

import bisect



N = int(eval(input()))

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

A.reverse()



d = []

for i in range(N):

    p = bisect.bisect_right(d, A[i])

    if p==len(d):

        d.append(A[i])

    else:

        d[p] = A[i]

ans = len(d)

print(ans)

import sys

input = sys.stdin.readline
from collections import deque
import bisect

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])
    if p == 0:
        d.appendleft(A[i])
    else:
        d[p - 1] = A[i]
ans = len(d)
print(ans)

import sys

input = sys.stdin.readline
from collections import deque
import bisect

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A.reverse()
d = []
for i in range(N):
    p = bisect.bisect_right(d, A[i])
    if p == len(d):
        d.append(A[i])
    else:
        d[p] = A[i]
ans = len(d)
print(ans)

-d = deque() +A.reverse() +d = [] -    p = bisect.bisect_left(d, A[i]) -    if p == 0: -        d.appendleft(A[i]) +    p = bisect.bisect_right(d, A[i]) +    if p == len(d): +        d.append(A[i]) -        d[p - 1] = A[i] +        d[p] = A[i]