N = int(eval(input()))

A = [int(eval(input())) for _ in range(N)]



from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort



def solve(N,A):

    ans = 0

    lis = []

    for i in range(N):

        ind = bisect_right(lis,-A[i])

        if ind == len(lis):

            lis.append(-A[i])

        else:

            lis[ind] = -A[i]

    ans = len(lis)

    return ans

print((solve(N,A)))
from bisect import *

def solve():

    ans = 0

    N = int(eval(input()))

    A = [-int(eval(input())) for _ in range(N)]

    lis = [A[0]]

    for i in range(1,N):

        if A[i]>=lis[-1]:

            lis.append(A[i])

        else:

            ind = bisect_right(lis,A[i])

            lis[ind] = A[i]

    ans = len(lis)

    return ans

print((solve()))
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort


def solve(N, A):
    ans = 0
    lis = []
    for i in range(N):
        ind = bisect_right(lis, -A[i])
        if ind == len(lis):
            lis.append(-A[i])
        else:
            lis[ind] = -A[i]
    ans = len(lis)
    return ans


print((solve(N, A)))

from bisect import *


def solve():
    ans = 0
    N = int(eval(input()))
    A = [-int(eval(input())) for _ in range(N)]
    lis = [A[0]]
    for i in range(1, N):
        if A[i] >= lis[-1]:
            lis.append(A[i])
        else:
            ind = bisect_right(lis, A[i])
            lis[ind] = A[i]
    ans = len(lis)
    return ans


print((solve()))

-N = int(eval(input())) -A = [int(eval(input())) for _ in range(N)] -from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort +from bisect import * -def solve(N, A): +def solve(): -    lis = [] -    for i in range(N): -        ind = bisect_right(lis, -A[i]) -        if ind == len(lis): -            lis.append(-A[i]) +    N = int(eval(input())) +    A = [-int(eval(input())) for _ in range(N)] +    lis = [A[0]] +    for i in range(1, N): +        if A[i] >= lis[-1]: +            lis.append(A[i]) -            lis[ind] = -A[i] +            ind = bisect_right(lis, A[i]) +            lis[ind] = A[i] -print((solve(N, A))) +print((solve()))