n=int(eval(input()))

tail=[int(eval(input()))]

import bisect

from collections import deque

tail=deque(tail)

c=1

for i in range(n-1):

    a=int(eval(input()))

    p=bisect.bisect_left(tail,a)

    if p==0:

        tail.appendleft(a)

        c+=1

    else:

        tail[p-1]=a

print(c)

import sys

input=sys.stdin.readline

n=int(eval(input()))

a_list=[int(eval(input())) for i in range(n)]

a_list.reverse()

INF=10**10

dp=[INF]*n

import bisect

for i in range(n):

    a=a_list[i]

    x=bisect.bisect_right(dp,a)

    dp[x]=a

ans=0

for i in range(n):

    if dp[i]!=INF:

        ans=i+1

print(ans)

n = int(eval(input()))
tail = [int(eval(input()))]
import bisect
from collections import deque

tail = deque(tail)
c = 1
for i in range(n - 1):
    a = int(eval(input()))
    p = bisect.bisect_left(tail, a)
    if p == 0:
        tail.appendleft(a)
        c += 1
    else:
        tail[p - 1] = a
print(c)

import sys

input = sys.stdin.readline
n = int(eval(input()))
a_list = [int(eval(input())) for i in range(n)]
a_list.reverse()
INF = 10**10
dp = [INF] * n
import bisect

for i in range(n):
    a = a_list[i]
    x = bisect.bisect_right(dp, a)
    dp[x] = a
ans = 0
for i in range(n):
    if dp[i] != INF:
        ans = i + 1
print(ans)

+import sys + +input = sys.stdin.readline -tail = [int(eval(input()))] +a_list = [int(eval(input())) for i in range(n)] +a_list.reverse() +INF = 10**10 +dp = [INF] * n -from collections import deque -tail = deque(tail) -c = 1 -for i in range(n - 1): -    a = int(eval(input())) -    p = bisect.bisect_left(tail, a) -    if p == 0: -        tail.appendleft(a) -        c += 1 -    else: -        tail[p - 1] = a -print(c) +for i in range(n): +    a = a_list[i] +    x = bisect.bisect_right(dp, a) +    dp[x] = a +ans = 0 +for i in range(n): +    if dp[i] != INF: +        ans = i + 1 +print(ans)