import bisect


n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
L = []
L.append(a[0])
for i in range(1,n):
    p = bisect.bisect_right(L, a[i])
    if L[-1] == a[i]:
        continue;
    elif p == len(L):
        L.append(a[i])
    else:
        if L[p-1] != a[i]:
            L[p] = a[i]
print(len(L))

