import bisect

n = int(eval(input()))

a = [int(eval(input())) for i in range(n)]

ans = 0

color = [a[n-1]]

for i in range(n-2,-1,-1):

    if a[i]>=color[-1]:

        color.append(a[i])

    else:

        x = bisect.bisect_right(color,a[i])

        color[x] = a[i]

print((len(color)))
import sys

import bisect

input = sys.stdin.readline

n = int(eval(input()))

a = [int(eval(input())) for i in range(n)]

ans = 0

color = [a[n-1]]

for i in range(n-2,-1,-1):

    if a[i]>=color[-1]:

        color.append(a[i])

    else:

        x = bisect.bisect_right(color,a[i])

        color[x] = a[i]

print((len(color)))
import bisect

n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
ans = 0
color = [a[n - 1]]
for i in range(n - 2, -1, -1):
    if a[i] >= color[-1]:
        color.append(a[i])
    else:
        x = bisect.bisect_right(color, a[i])
        color[x] = a[i]
print((len(color)))

import sys
import bisect

input = sys.stdin.readline
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
ans = 0
color = [a[n - 1]]
for i in range(n - 2, -1, -1):
    if a[i] >= color[-1]:
        color.append(a[i])
    else:
        x = bisect.bisect_right(color, a[i])
        color[x] = a[i]
print((len(color)))

+import sys +input = sys.stdin.readline