module agc61
 implicit none
contains
 subroutine agc61a(a,x,y)
  integer(8),intent(in)::x,y
  integer(8),intent(inout)::a(:)
  a(x)=y
 end subroutine agc61a
 function agc61b(a,x,y)result(ans)
  integer(8),intent(in)::a(:),x,y
  integer(8)::ans
  ans=maxval(a(x:y))
 end function agc61b
 function agc61c(a,x,y,N)result(ans)
  integer(8),intent(in)::a(:),x,y,N
  integer(8)::ans,ia,c
  c=0
  do ia=x,N
   if(a(ia)>=y)then
    c=ia
    exit
   end if
  end do
  if(c==0)then
   ans=N+1
  else
   ans=c
  end if
 end function agc61c
end module agc61

program abc61
 use agc61
 implicit none
 integer(8)::N,Q,p,x,y,ia,ib
 integer(8),allocatable::a(:)
 read(*,*)N,Q
 allocate(a(N))
 read(*,*)(a(ia),ia=1,N)
 do ib=1,Q
  read(*,*)p,x,y
  if(p==1)then
   call agc61a(a,x,y)
  else if(p==2)then
   print'(i0)',agc61b(a,x,y)
  else
   print'(i0)',agc61c(a,x,y,N)
  end if
 end do
 deallocate(a)
end program abc61