import bisect


n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
    
longest = [0]
longest[0] = a[0]
for i in range(1, n):
    if longest[-1] < a[i]:
        longest.append(a[i])
    else:
        j = bisect.bisect_right(longest, a[i])
        if longest[j-1] == a[i]:
            longest[j-1] == a[i]
        else:
            longest[j] = a[i]

print(len(longest))
