import sys

import bisect



inf = float('inf')



def solve():

    n = int(input())

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

    dp = [inf] * n

    max_ = 1



    for a in A:

        j = bisect.bisect_left(dp, a, lo=0, hi=max_)

        max_ = max(max_, j + 1)

        dp[j] = a



    # print(dp)

    ans = max_

    print(ans)





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

import bisect



inf = float('inf')



def solve():

    n = int(input())

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

    dp = [inf] * n

    # max_ = 1



    for a in A:

        j = bisect.bisect_left(dp, a)

        # max_ = max(max_, j + 1)

        dp[j] = a



    # print(dp)



    ans = 1

    for i, v in enumerate(dp):

        if v == inf:

            ans = i

            break

    else:

        ans = n

        

    print(ans)





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
import bisect

inf = float("inf")


def solve():
    n = int(input())
    A = [int(input()) for i in range(n)]
    dp = [inf] * n
    max_ = 1
    for a in A:
        j = bisect.bisect_left(dp, a, lo=0, hi=max_)
        max_ = max(max_, j + 1)
        dp[j] = a
    # print(dp)
    ans = max_
    print(ans)


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
import bisect

inf = float("inf")


def solve():
    n = int(input())
    A = [int(input()) for i in range(n)]
    dp = [inf] * n
    # max_ = 1
    for a in A:
        j = bisect.bisect_left(dp, a)
        # max_ = max(max_, j + 1)
        dp[j] = a
    # print(dp)
    ans = 1
    for i, v in enumerate(dp):
        if v == inf:
            ans = i
            break
    else:
        ans = n
    print(ans)


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

-    max_ = 1 +    # max_ = 1 -        j = bisect.bisect_left(dp, a, lo=0, hi=max_) -        max_ = max(max_, j + 1) +        j = bisect.bisect_left(dp, a) +        # max_ = max(max_, j + 1) -    ans = max_ +    ans = 1 +    for i, v in enumerate(dp): +        if v == inf: +            ans = i +            break +    else: +        ans = n