import sys, bisect



def solve():

    A = list(map(int, sys.stdin.readlines()))

    n = A[0]

    A = A[1:]

    L = A[:1]

    for a_i in A[1:]:

        if a_i > L[-1]:

            L.append(a_i)

        else:

            j = bisect.bisect_left(L, a_i)

            L[j] = a_i

    print((len(L)))



solve()
import sys

from bisect import bisect_left



def solve():

    A = list(map(int, sys.stdin))

    n = next(A)

    L = [next(A)]

    for a_i in A:

        if a_i > L[-1]:

            L.append(a_i)

        else:

            j = bisect_left(L, a_i)

            L[j] = a_i

    print((len(L)))



solve()



import sys, bisect


def solve():
    A = list(map(int, sys.stdin.readlines()))
    n = A[0]
    A = A[1:]
    L = A[:1]
    for a_i in A[1:]:
        if a_i > L[-1]:
            L.append(a_i)
        else:
            j = bisect.bisect_left(L, a_i)
            L[j] = a_i
    print((len(L)))


solve()

import sys
from bisect import bisect_left


def solve():
    A = list(map(int, sys.stdin))
    n = next(A)
    L = [next(A)]
    for a_i in A:
        if a_i > L[-1]:
            L.append(a_i)
        else:
            j = bisect_left(L, a_i)
            L[j] = a_i
    print((len(L)))


solve()

-import sys, bisect +import sys +from bisect import bisect_left -    A = list(map(int, sys.stdin.readlines())) -    n = A[0] -    A = A[1:] -    L = A[:1] -    for a_i in A[1:]: +    A = list(map(int, sys.stdin)) +    n = next(A) +    L = [next(A)] +    for a_i in A: -            j = bisect.bisect_left(L, a_i) +            j = bisect_left(L, a_i)