import sys

input = sys.stdin.readline

import bisect



INF = 10 ** 18

N = int(eval(input()))

A = [10 ** 10 - int(eval(input())) for _ in range(N)] # 逆順にしておく



# 最長単調減少列：狭義



dp = [INF] * (N+1) # 長さ、その長さの末端としてありうる最大値



for a in A:

    idx = bisect.bisect_right(dp,a)

    dp[idx] = a



answer = bisect.bisect_left(dp, INF)

print(answer)
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



from bisect import bisect_right



N,*A = list(map(int,read().split()))



def LIS(seq):

    # 狭義

    N = len(seq)

    INF = 10**18

    dp = [INF] * (N+1)

    for x in seq:

        i = bisect_right(dp,x)

        dp[i] = x

    return bisect_right(dp,INF-1)



answer = LIS([-x for x in A])

print(answer)
import sys

input = sys.stdin.readline
import bisect

INF = 10**18
N = int(eval(input()))
A = [10**10 - int(eval(input())) for _ in range(N)]  # 逆順にしておく
# 最長単調減少列：狭義
dp = [INF] * (N + 1)  # 長さ、その長さの末端としてありうる最大値
for a in A:
    idx = bisect.bisect_right(dp, a)
    dp[idx] = a
answer = bisect.bisect_left(dp, INF)
print(answer)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from bisect import bisect_right

N, *A = list(map(int, read().split()))


def LIS(seq):
    # 狭義
    N = len(seq)
    INF = 10**18
    dp = [INF] * (N + 1)
    for x in seq:
        i = bisect_right(dp, x)
        dp[i] = x
    return bisect_right(dp, INF - 1)


answer = LIS([-x for x in A])
print(answer)

-input = sys.stdin.readline -import bisect +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +from bisect import bisect_right -INF = 10**18 -N = int(eval(input())) -A = [10**10 - int(eval(input())) for _ in range(N)]  # 逆順にしておく -# 最長単調減少列：狭義 -dp = [INF] * (N + 1)  # 長さ、その長さの末端としてありうる最大値 -for a in A: -    idx = bisect.bisect_right(dp, a) -    dp[idx] = a -answer = bisect.bisect_left(dp, INF) +N, *A = list(map(int, read().split())) + + +def LIS(seq): +    # 狭義 +    N = len(seq) +    INF = 10**18 +    dp = [INF] * (N + 1) +    for x in seq: +        i = bisect_right(dp, x) +        dp[i] = x +    return bisect_right(dp, INF - 1) + + +answer = LIS([-x for x in A])