from bisect import bisect_right as br

N = int(eval(input()))

inf = 10 ** 9 + 1

lis = [inf] * (N + 1)

res = 0

for _ in range(N):

  a = -int(eval(input()))

  ind = br(lis, a)

  if a <= lis[ind]:

    lis[ind] = a



for i in range(1, N + 1):

  if lis[i] == inf:

    break

  res = i

print((res + 1))
import sys

from bisect import bisect_right as br

input = sys.stdin.readline

N = int(eval(input()))

a = []

for _ in range(N): a.append(int(eval(input())))

lis = [float("inf") for _ in range(N)]

reva = a[: : -1]



for i in range(N):

  j = br(lis, reva[i])

  lis[j] = reva[i]



res = N

for i in range(N):

  if lis[i] == float("inf"):

    res = i

    break

print(res)
from bisect import bisect_right as br

N = int(eval(input()))
inf = 10**9 + 1
lis = [inf] * (N + 1)
res = 0
for _ in range(N):
    a = -int(eval(input()))
    ind = br(lis, a)
    if a <= lis[ind]:
        lis[ind] = a
for i in range(1, N + 1):
    if lis[i] == inf:
        break
    res = i
print((res + 1))

import sys
from bisect import bisect_right as br

input = sys.stdin.readline
N = int(eval(input()))
a = []
for _ in range(N):
    a.append(int(eval(input())))
lis = [float("inf") for _ in range(N)]
reva = a[::-1]
for i in range(N):
    j = br(lis, reva[i])
    lis[j] = reva[i]
res = N
for i in range(N):
    if lis[i] == float("inf"):
        res = i
        break
print(res)

+import sys +input = sys.stdin.readline -inf = 10**9 + 1 -lis = [inf] * (N + 1) -res = 0 +a = [] -    a = -int(eval(input())) -    ind = br(lis, a) -    if a <= lis[ind]: -        lis[ind] = a -for i in range(1, N + 1): -    if lis[i] == inf: +    a.append(int(eval(input()))) +lis = [float("inf") for _ in range(N)] +reva = a[::-1] +for i in range(N): +    j = br(lis, reva[i]) +    lis[j] = reva[i] +res = N +for i in range(N): +    if lis[i] == float("inf"): +        res = i -    res = i -print((res + 1)) +print(res)