integer mi,ma,md
integer N
integer cnt
integer,allocatable,dimension(:)::mins
integer A
read*,N
read*,A
mins=[A]
cnt=1
do i=2,N
  read*,A
  if(A>mins(1))then
    mi=1 !miは絶対にたどり着く上限
    ma=cnt+1 
    do while(mi+1<ma)
      md=(mi+ma)/2
      if(mins(md)<A)then
        mi=md
      else
        ma=md
      endif
    end do
    mins(mi)=A
  else
    mins=[A,mins]
    cnt=cnt+1
  end if
end do
print"(I0)",cnt
end