
import bisect


def lis():
    L.append(A[0])
    length = 1
    
    for i in range(1, n):
        if L[length-1] < A[i]:
            L.append(A[i])
            length += 1
        else:
            if L[bisect.bisect_left(L, A[i])] >= A[i]:
                L[bisect.bisect_left(L, A[i])] = A[i]
            else:
                L[bisect.bisect_right(L, A[i])] = A[i]
    return length


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

print(lis())













