def bisect(lst, isok, ok, ng):
    while(abs(ok-ng)>1):
        mid = (ok+ng)//2
        if isok(lst[mid]):
            ok = mid
        else:
            ng = mid
    return ok

n = int(input())
a = [int(input()) for i in range(n)]
inf = 10**10
dp = [inf] * (n+1)
dp[0] = -1
for i in a:
    ind = bisect(dp, lambda x:x < i, -1, n+1) #dpは単調増加列なのでbisectが使える
    dp[ind+1] = min(dp[ind+1], i)

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