from bisect import bisect
import sys
n = int(input())
A = [int(i.rstrip("\n")) for i in sys.stdin.readlines()]
 #?????????i+1??§???????¢??????¨??????????????????????´????????°???????????´?
L = []
def LIS():
    L.append(A[0])
    length = 0
    for i in range(n):
        if L[length] < A[i]:
            length += 1
            L.append(A[i])
        else:
            if A[i] in L: continue
            j = bisect(L, A[i], 0, length) #L????????§?????????A[i]??\?????¨????????????????????????
            L[j] = A[i]
    return length + 1

print(LIS())