import sys

import bisect

from collections import deque

input = sys.stdin.readline

n = int(input().strip())

q = deque()

qappL = q.appendleft

for i in range(n):

  a = int(input().strip())

  b = bisect.bisect_left(q,a)

  if b == 0:

    qappL(a)

  else:

    q[b-1] = a

print((len(q)))
import sys

import bisect

input = sys.stdin.readline

n = int(input().strip())

q = [-int(input().strip())]

qapp = q.append

bis_r = bisect.bisect_right

for i in range(n-1):

  a = -int(input().strip())

  if q[-1] <= a:

    qapp(a)

  else:

    b = bis_r(q,a)

    q[b] = a

print((len(q)))
import sys
import bisect
from collections import deque

input = sys.stdin.readline
n = int(input().strip())
q = deque()
qappL = q.appendleft
for i in range(n):
    a = int(input().strip())
    b = bisect.bisect_left(q, a)
    if b == 0:
        qappL(a)
    else:
        q[b - 1] = a
print((len(q)))

import sys
import bisect

input = sys.stdin.readline
n = int(input().strip())
q = [-int(input().strip())]
qapp = q.append
bis_r = bisect.bisect_right
for i in range(n - 1):
    a = -int(input().strip())
    if q[-1] <= a:
        qapp(a)
    else:
        b = bis_r(q, a)
        q[b] = a
print((len(q)))

-from collections import deque -q = deque() -qappL = q.appendleft -for i in range(n): -    a = int(input().strip()) -    b = bisect.bisect_left(q, a) -    if b == 0: -        qappL(a) +q = [-int(input().strip())] +qapp = q.append +bis_r = bisect.bisect_right +for i in range(n - 1): +    a = -int(input().strip()) +    if q[-1] <= a: +        qapp(a) -        q[b - 1] = a +        b = bis_r(q, a) +        q[b] = a