from bisect import *

n = eval(input())

dp = [10**10]*(n+1)

dp[0] = -1

for i in range(n):

    a = eval(input())

    idx = bisect(dp, a-1)

    dp[idx] = min(a, dp[idx])

print(bisect(dp, 10**10-1)-1)
from bisect import *

import sys



def solve(N, A):

    INF = 10**10



    dp = [INF]*(N+1)

    dp[0] = -1

    for a in A:

        idx = bisect(dp, a-1)

        dp[idx] = min(a, dp[idx])

    return max(i for i in range(N+1) if dp[i] < INF)



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

sys.stdout.write("%d\n" % solve(N, A))

from bisect import *

n = eval(input())
dp = [10**10] * (n + 1)
dp[0] = -1
for i in range(n):
    a = eval(input())
    idx = bisect(dp, a - 1)
    dp[idx] = min(a, dp[idx])
print(bisect(dp, 10**10 - 1) - 1)

from bisect import *
import sys


def solve(N, A):
    INF = 10**10
    dp = [INF] * (N + 1)
    dp[0] = -1
    for a in A:
        idx = bisect(dp, a - 1)
        dp[idx] = min(a, dp[idx])
    return max(i for i in range(N + 1) if dp[i] < INF)


N, *A = list(map(int, sys.stdin.read().split()))
sys.stdout.write("%d\n" % solve(N, A))

+import sys -n = eval(input()) -dp = [10**10] * (n + 1) -dp[0] = -1 -for i in range(n): -    a = eval(input()) -    idx = bisect(dp, a - 1) -    dp[idx] = min(a, dp[idx]) -print(bisect(dp, 10**10 - 1) - 1) + +def solve(N, A): +    INF = 10**10 +    dp = [INF] * (N + 1) +    dp[0] = -1 +    for a in A: +        idx = bisect(dp, a - 1) +        dp[idx] = min(a, dp[idx]) +    return max(i for i in range(N + 1) if dp[i] < INF) + + +N, *A = list(map(int, sys.stdin.read().split())) +sys.stdout.write("%d\n" % solve(N, A))