from bisect import bisect_right



def main():    

    N = int(eval(input()))

    A = [int(eval(input())) for i in range(N)]

    n = [A.pop(-1)]

    A.reverse()

    

    for a in A:

        if n[-1] <= a: n.append(a)

        else: n[bisect_right(n, a)] = a

    

    print((len(n)))



if __name__ == '__main__':

    main()
import sys

from bisect import bisect_right



input = sys.stdin.readline



def main():

    N = int(eval(input()))

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

    n = [A.pop(-1)]

    A.reverse()

    

    for a in A:

        if n[-1] <= a: n.append(a)

        else: n[bisect_right(n, a)] = a

    

    print((len(n)))



if __name__ == '__main__':

    main()
from bisect import bisect_right


def main():
    N = int(eval(input()))
    A = [int(eval(input())) for i in range(N)]
    n = [A.pop(-1)]
    A.reverse()
    for a in A:
        if n[-1] <= a:
            n.append(a)
        else:
            n[bisect_right(n, a)] = a
    print((len(n)))


if __name__ == "__main__":
    main()

import sys
from bisect import bisect_right

input = sys.stdin.readline


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


if __name__ == "__main__":
    main()

+import sys + +input = sys.stdin.readline -    A = [int(eval(input())) for i in range(N)] +    A = [int(eval(input())) for _ in range(N)]