import Data.Array
import Data.Array.ST
naive_rec::Array Int Int -> Int -> Int
naive_rec ar idx = if idx == 0 then 0 else maximum [(naive_rec ar j)+1|j<-[0..(idx-1)],(j==0)||(ar!j)<(ar!idx)]

naive_rec_solver::[Int]->Int->Int
naive_rec_solver ls size = let ar = listArray (1,size) ls in
                           maximum ( map (naive_rec ar) [0..size])


{-
STによる明示的な配列操作DP

まって、本当に再帰リストできない？lがあるものとして、これの前半しかつかわない。次は十分速いか？
-}

memo_ls::Array Int Int ->Int->[Int]
memo_ls ar size = 0:[ let prev = take k (zip (memo_ls ar size) [0..]) in
                      let cond = (\idx -> if idx == 0 then True else (ar!idx)<(ar!k)) in
                      maximum [l+1|(l,idx)<-prev,cond idx]
                    | k <-[1..size] ]

memo_ls_solver::[Int]->Int->Int
memo_ls_solver ls size = let ar = listArray (1,size) ls in
                         maximum (memo_ls ar size)

n_get::Int->IO [Int]
n_get 0 = return []
n_get n = do
  c<-getLine
  rest<-n_get (n-1)
  return ((read c):rest)

main::IO()
main=do
  nc<-getLine
  let n = read nc
  dat<-n_get n
  print (memo_ls_solver dat n)
