import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    d = []
    for _ in range(n):
        tmp = ni()
        d.append(tmp)

    dp = [INF for _ in range(n + 1)]

    for di in d:
        idx = bisect.bisect_left(dp, di)
        dp[idx] = di

    for i in range(n, -1, -1):
        if dp[i] != INF:
            print(i + 1)
            break


if __name__ == '__main__':
    main()

