import bisect

N = int(eval(input()))

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

b = []

for a in A[::-1]:

  idx = bisect.bisect_right(b, a)

  if len(b) <= idx:

    b.append(a)

  else:

    b[idx] = a



print((len(b)))

import bisect

import sys

input = sys.stdin.readline

N = int(eval(input()))

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



dp = [float('inf')]*(N+1)

for a in A[::-1]:

  idx = bisect.bisect_right(dp, a)

  dp[idx] = a



ans = 0

for n in dp:

  if n != float('inf'):

    ans += 1

print(ans)
import bisect

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
b = []
for a in A[::-1]:
    idx = bisect.bisect_right(b, a)
    if len(b) <= idx:
        b.append(a)
    else:
        b[idx] = a
print((len(b)))

import bisect
import sys

input = sys.stdin.readline
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
dp = [float("inf")] * (N + 1)
for a in A[::-1]:
    idx = bisect.bisect_right(dp, a)
    dp[idx] = a
ans = 0
for n in dp:
    if n != float("inf"):
        ans += 1
print(ans)

+import sys +input = sys.stdin.readline -b = [] +dp = [float("inf")] * (N + 1) -    idx = bisect.bisect_right(b, a) -    if len(b) <= idx: -        b.append(a) -    else: -        b[idx] = a -print((len(b))) +    idx = bisect.bisect_right(dp, a) +    dp[idx] = a +ans = 0 +for n in dp: +    if n != float("inf"): +        ans += 1 +print(ans)