import sys
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]
INF = 10**18
arr = [INF]*(N+1)
arr[0] = -1
for a in A:
    l, r = 0, N
    while (r-l) > 1:
        mid = (r+l)//2
        if arr[mid] < a:
            l = mid
        else:
            r = mid
    arr[r] = a
for i in range(N, 0, -1):
    if arr[i] != INF:
        print(i)
        break
