import sys

from bisect import bisect_left



def solve():

    n = int(input())

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



    inf = 10**9 + 1

    dp = [inf] * n



    for a in A:

        j = bisect_left(dp, a)

        dp[j] = a



    for i, v in enumerate(dp):

        if v == inf:

            print(i)

            return



    print(n)



def debug(x, table):

    for name, val in table.items():

        if x is val:

            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)

            return None



if __name__ == '__main__':

    solve()

from sys import stdin

from bisect import bisect_left



def solve():

    n = int(stdin.readline())

    A = [int(stdin.readline()) for i in range(n)]



    inf = 10**9 + 1

    dp = [inf] * n



    for a in A:

        j = bisect_left(dp, a)

        dp[j] = a



    for i, v in enumerate(dp):

        if v == inf:

            print(i)

            return



    print(n)



def debug(x, table):

    for name, val in table.items():

        if x is val:

            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)

            return None



if __name__ == '__main__':

    solve()

import sys
from bisect import bisect_left


def solve():
    n = int(input())
    A = [int(input()) for i in range(n)]
    inf = 10**9 + 1
    dp = [inf] * n
    for a in A:
        j = bisect_left(dp, a)
        dp[j] = a
    for i, v in enumerate(dp):
        if v == inf:
            print(i)
            return
    print(n)


def debug(x, table):
    for name, val in table.items():
        if x is val:
            print("DEBUG:{} -> {}".format(name, val), file=sys.stderr)
            return None


if __name__ == "__main__":
    solve()

from sys import stdin
from bisect import bisect_left


def solve():
    n = int(stdin.readline())
    A = [int(stdin.readline()) for i in range(n)]
    inf = 10**9 + 1
    dp = [inf] * n
    for a in A:
        j = bisect_left(dp, a)
        dp[j] = a
    for i, v in enumerate(dp):
        if v == inf:
            print(i)
            return
    print(n)


def debug(x, table):
    for name, val in table.items():
        if x is val:
            print("DEBUG:{} -> {}".format(name, val), file=sys.stderr)
            return None


if __name__ == "__main__":
    solve()

-import sys +from sys import stdin -    n = int(input()) -    A = [int(input()) for i in range(n)] +    n = int(stdin.readline()) +    A = [int(stdin.readline()) for i in range(n)]