from bisect import bisect
import sys


if __name__ == "__main__":
    n = int(input())
    a = [0] * n
    for i in range(n):
        a[i] = int(input())

    dp = [sys.maxsize] * (n + 1)
    dp[0] = -1

    for elem in a:
        idx = bisect(dp, elem - 1)
        dp[idx] = min(elem, dp[idx])

    ans = max(i for i in range(n + 1) if dp[i] < sys.maxsize)
    print(ans)

