integer mi,ma,md
integer N
integer cnt
integer,allocatable,dimension(:)::mins
integer A
read*,N
read*,A
allocate(mins(N))
cnt=1
mins(1)=A
do i=2,N
  read*,A
  if(A>mins(cnt))then
    mi=0
    ma=cnt 
    do while(mi+1<ma)
      md=(mi+ma-1)/2+1
      if(mins(md)<A)then
        ma=md
      else
        mi=md
      endif
    end do
    mins(ma)=A
  else
    cnt=cnt+1
    mins(cnt)=A
  end if
end do
print"(I0)",cnt
end