import sys

from bisect import bisect_left



input = sys.stdin.readline





def main():

    N = int(eval(input()))

    A = [0] * N

    for i in range(N):

        A[i] = int(eval(input()))



    colors = []

    for a in A:

        idx = bisect_left(colors, a)

        if idx == 0:

            colors.insert(0, a)

        else:

            colors[idx - 1] = a



    ans = len(colors)

    print(ans)





if __name__ == "__main__":

    main()

import sys

from bisect import bisect_right



input = sys.stdin.readline





def main():

    N = int(eval(input()))

    A = [0] * N

    for i in range(N):

        A[i] = int(eval(input()))



    A = [-a for a in A]



    colors = []

    for a in A:

        idx = bisect_right(colors, a)

        if idx == len(colors):

            colors.append(a)

        else:

            colors[idx] = a



    ans = len(colors)

    print(ans)





if __name__ == "__main__":

    main()

import sys
from bisect import bisect_left

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    A = [0] * N
    for i in range(N):
        A[i] = int(eval(input()))
    colors = []
    for a in A:
        idx = bisect_left(colors, a)
        if idx == 0:
            colors.insert(0, a)
        else:
            colors[idx - 1] = a
    ans = len(colors)
    print(ans)


if __name__ == "__main__":
    main()

import sys
from bisect import bisect_right

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    A = [0] * N
    for i in range(N):
        A[i] = int(eval(input()))
    A = [-a for a in A]
    colors = []
    for a in A:
        idx = bisect_right(colors, a)
        if idx == len(colors):
            colors.append(a)
        else:
            colors[idx] = a
    ans = len(colors)
    print(ans)


if __name__ == "__main__":
    main()

-from bisect import bisect_left +from bisect import bisect_right +    A = [-a for a in A] -        idx = bisect_left(colors, a) -        if idx == 0: -            colors.insert(0, a) +        idx = bisect_right(colors, a) +        if idx == len(colors): +            colors.append(a) -            colors[idx - 1] = a +            colors[idx] = a