from collections import deque

from bisect import bisect_left

n = int(eval(input()))

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

ans = deque([a[0]])

for a_i in a[1:]:

    if ans[0] < a_i:

        i = bisect_left(ans, a_i)

        ans[i-1] = a_i

    else:

        ans.appendleft(a_i)



print((len(ans)))





from bisect import bisect_right

n = int(eval(input()))



color = [0] * (n+1)

for i in range(n):

    a = int(eval(input()))

    j = bisect_right(color, a)

    color[j-1] = a+1



ans = 0

for t in color:

    if t != 0:

        ans += 1



print(ans)



from collections import deque
from bisect import bisect_left

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
ans = deque([a[0]])
for a_i in a[1:]:
    if ans[0] < a_i:
        i = bisect_left(ans, a_i)
        ans[i - 1] = a_i
    else:
        ans.appendleft(a_i)
print((len(ans)))

from bisect import bisect_right

n = int(eval(input()))
color = [0] * (n + 1)
for i in range(n):
    a = int(eval(input()))
    j = bisect_right(color, a)
    color[j - 1] = a + 1
ans = 0
for t in color:
    if t != 0:
        ans += 1
print(ans)

-from collections import deque -from bisect import bisect_left +from bisect import bisect_right -a = [int(eval(input())) for _ in range(n)] -ans = deque([a[0]]) -for a_i in a[1:]: -    if ans[0] < a_i: -        i = bisect_left(ans, a_i) -        ans[i - 1] = a_i -    else: -        ans.appendleft(a_i) -print((len(ans))) +color = [0] * (n + 1) +for i in range(n): +    a = int(eval(input())) +    j = bisect_right(color, a) +    color[j - 1] = a + 1 +ans = 0 +for t in color: +    if t != 0: +        ans += 1 +print(ans)