import bisect

n=int(input())
seq=[int(input()) for _ in range(n)]

dp=[seq[0]]
for num in seq:
    if num > dp[-1]:
        dp.append(num)
    else:
        dp[bisect.bisect_left(dp,num)] = num

print(len(dp))
