program main
 implicit none
 integer n,val,ind,i,j
 integer, allocatable::a(:)
 read(*,*) n
 allocate(a(1:n))
 do i=1,n
  a(i) = -1
 end do
 read(*,*) val
 ind = 1
 a(1) = val
 do i=2,n
  read(*,*) val
  if(a(ind) >= val) then
   a(ind+1) = val
   ind = ind+1
  else
   do j=1,ind
    if(a(j) < val) then
     a(j) = val
     exit
    end if
   end do
  end if
 end do
 write(*,*) ind
end program main