# coding: utf-8
# Your code here!

import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,*a = map(int,read().split())

#dp[i] = 長さiのLISの最後尾の最小値 
from bisect import bisect_left
INF = 2*10**9
dp = [INF]*n
for ai in a:
    dp[bisect_left(dp,ai)] = ai
ans = bisect_left(dp,INF)
print(ans)

