import bisect

n = int(eval(input()))

A = [int(eval(input())) for j in range(n)]

dp = A[:1]

for a_i in A[1:]:

    if dp[-1] < a_i:

        dp.append(a_i)

    else:

        dp[bisect.bisect_left(dp, a_i)] = a_i

print((len(dp)))
import sys

import bisect

n = int(sys.stdin.readline())

A = [int(sys.stdin.readline()) for j in range(n)]

dp = A[:1]

for a_i in A[1:]:

    if dp[-1] < a_i:

        dp.append(a_i)

    else:

        dp[bisect.bisect_left(dp, a_i)] = a_i

print((len(dp)))
import bisect

n = int(eval(input()))
A = [int(eval(input())) for j in range(n)]
dp = A[:1]
for a_i in A[1:]:
    if dp[-1] < a_i:
        dp.append(a_i)
    else:
        dp[bisect.bisect_left(dp, a_i)] = a_i
print((len(dp)))

import sys
import bisect

n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for j in range(n)]
dp = A[:1]
for a_i in A[1:]:
    if dp[-1] < a_i:
        dp.append(a_i)
    else:
        dp[bisect.bisect_left(dp, a_i)] = a_i
print((len(dp)))

+import sys -n = int(eval(input())) -A = [int(eval(input())) for j in range(n)] +n = int(sys.stdin.readline()) +A = [int(sys.stdin.readline()) for j in range(n)]