n = int(input())

A = []
for _ in range(n):
    A.append(int(input()))

dp = [0 for _ in range(n)]
dp[0] = A[0]
len = 1

def CeilIndex(A, l, r, key):
    while r-l > 1:
        m = (l+r) // 2
        if A[m] >= key:
            r = m
        else:
            l = m
    return r

for i in range(1, n):
    #print(A[i], dp)
    if A[i] < dp[0]:
        dp[0] = A[i]
    elif A[i] > dp[len-1]:
        dp[len] = A[i]
        len += 1
    else:
        dp[CeilIndex(dp, -1, len-1, A[i])] = A[i]
print(len)


