# -*- coding: utf-8 -*-
from bisect import bisect
N = int(input())
A = [int(input()) for _ in range(N)]
L = [A[0]]

for i in range(1, N):
    if L[-1] < A[i]:
        L.append(A[i])
    else:
        L[bisect(L, A[i])]  = A[i]
print(len(L))