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()))



    dp = [A.pop()]

    for a in reversed(A):

        if a >= dp[-1]:

            dp.append(a)

        else:

            dp[bisect_right(dp, a)] = a



    print((len(dp)))

    return





if __name__ == '__main__':

    main()

def main():

    import sys

    import bisect



    read = sys.stdin.buffer.read

    bisect_right = bisect.bisect_right



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



    dp = [A[-1]]

    for a in reversed(A[:-1]):

        if a >= dp[-1]:

            dp.append(a)

        else:

            dp[bisect_right(dp, a)] = a



    print((len(dp)))

    return





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()))
    dp = [A.pop()]
    for a in reversed(A):
        if a >= dp[-1]:
            dp.append(a)
        else:
            dp[bisect_right(dp, a)] = a
    print((len(dp)))
    return


if __name__ == "__main__":
    main()

def main():
    import sys
    import bisect

    read = sys.stdin.buffer.read
    bisect_right = bisect.bisect_right
    N, *A = list(map(int, read().split()))
    dp = [A[-1]]
    for a in reversed(A[:-1]):
        if a >= dp[-1]:
            dp.append(a)
        else:
            dp[bisect_right(dp, a)] = a
    print((len(dp)))
    return


if __name__ == "__main__":
    main()

-import sys -from bisect import bisect_right +def main(): +    import sys +    import bisect -read = sys.stdin.read -readline = sys.stdin.readline -readlines = sys.stdin.readlines -sys.setrecursionlimit(10**9) -INF = 1 << 60 - - -def main(): +    read = sys.stdin.buffer.read +    bisect_right = bisect.bisect_right -    dp = [A.pop()] -    for a in reversed(A): +    dp = [A[-1]] +    for a in reversed(A[:-1]):