import bisect
n = int(input())
L = []
for i in range(n):
    L.append(int(input()))
dp = [float('inf')]*n
for i in range(n):
    k = bisect.bisect_left(dp,L[i])
    dp[k] = L[i]
ans = 0
for i in range(n):
    if dp[i] != float('inf'):
        ans += 1
    else:
        break
print(ans)
