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



    vec = [A[-1]]

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

        if a >= vec[-1]:

            vec.append(a)

        else:

            vec[bisect_right(vec, a)] = a



    print((len(vec)))

    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()))
    vec = [A[-1]]
    for a in reversed(A[:-1]):
        if a >= vec[-1]:
            vec.append(a)
        else:
            vec[bisect_right(vec, a)] = a
    print((len(vec)))
    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 + + -    import sys -    import bisect - -    read = sys.stdin.buffer.read -    bisect_right = bisect.bisect_right -    dp = [A[-1]] +    vec = [A[-1]] -        if a >= dp[-1]: -            dp.append(a) +        if a >= vec[-1]: +            vec.append(a) -            dp[bisect_right(dp, a)] = a -    print((len(dp))) +            vec[bisect_right(vec, a)] = a +    print((len(vec)))