from sys import stdin, setrecursionlimit

from bisect import bisect_right



setrecursionlimit(10 ** 9)

INF = 1 << 60





def input():

    return stdin.readline().strip()





def main():

    N = int(eval(input()))

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

    B = [-A[0]]



    for a in A[1:]:

        if a <= -B[-1]:

            B.append(-a)

        else:

            B[bisect_right(B, -a)] = -a



    print((len(B)))





if __name__ == '__main__':

    main()

import sys

from bisect import bisect_right



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60





def main():

    N, *A = list(map(int, read().split()))



    A.reverse()



    dp = [A[0]]

    for a in A[1:]:

        if a >= dp[-1]:

            dp.append(a)

        else:

            dp[bisect_right(dp, a)] = a



    print((len(dp)))

    return





if __name__ == '__main__':

    main()

from sys import stdin, setrecursionlimit
from bisect import bisect_right

setrecursionlimit(10**9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


def main():
    N = int(eval(input()))
    A = tuple(int(eval(input())) for _ in range(N))
    B = [-A[0]]
    for a in A[1:]:
        if a <= -B[-1]:
            B.append(-a)
        else:
            B[bisect_right(B, -a)] = -a
    print((len(B)))


if __name__ == "__main__":
    main()

import sys
from bisect import bisect_right

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60


def main():
    N, *A = list(map(int, read().split()))
    A.reverse()
    dp = [A[0]]
    for a in A[1:]:
        if a >= dp[-1]:
            dp.append(a)
        else:
            dp[bisect_right(dp, a)] = a
    print((len(dp)))
    return


if __name__ == "__main__":
    main()

-from sys import stdin, setrecursionlimit +import sys -setrecursionlimit(10**9) +read = sys.stdin.read +readline = sys.stdin.readline +readlines = sys.stdin.readlines +sys.setrecursionlimit(10**9) -def input(): -    return stdin.readline().strip() - - -    N = int(eval(input())) -    A = tuple(int(eval(input())) for _ in range(N)) -    B = [-A[0]] +    N, *A = list(map(int, read().split())) +    A.reverse() +    dp = [A[0]] -        if a <= -B[-1]: -            B.append(-a) +        if a >= dp[-1]: +            dp.append(a) -            B[bisect_right(B, -a)] = -a -    print((len(B))) +            dp[bisect_right(dp, a)] = a +    print((len(dp))) +    return