output_description: For each query with T_i=2, 3, print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N Q
      A_1 A_2 \cdots A_N
      First query
      Second query
      \vdots
      Q-th query
      
  
  Each query is given in the following format:
  
  If T_i=1,3,
  
      
      
      T_i X_i V_i
      
  
  If T_i=2,
  
      
      
      T_i L_i R_i
attempt: from sys import stdin
  
  
  class SegmentTree:
      _op = None
      _e = None
      _size = None
      _offset = None
      _data = None
  
      def __init__(self, size, op, e):
          self._op = op
          self._e = e
          self._size = size
          t = 1
          while t < size:
              t *= 2
          self._offset = t - 1
          self._data = [0] * (t * 2 - 1)
  
      def build(self, iterable):
          op = self._op
          data = self._data
          data[self._offset : self._offset + self._size] = iterable
          for i in range(self._offset - 1, -1, -1):
              data[i] = op(data[i * 2 + 1], data[i * 2 + 2])
  
      def update(self, index, value):
          op = self._op
          data = self._data
          i = self._offset + index
          data[i] = value
          while i >= 1:
              i = (i - 1) // 2
              data[i] = op(data[i * 2 + 1], data[i * 2 + 2])
  
      def query(self, start, stop):
          def iter_segments(data, l, r):
              while l < r:
                  if l & 1 == 0:
                      yield data[l]
                  if r & 1 == 0:
                      yield data[r - 1]
                  l = l // 2
                  r = (r - 1) // 2
  
          op = self._op
          it = iter_segments(self._data, start + self._offset, stop + self._offset)
          result = self._e
          for e in it:
              result = op(result, e)
          return result
  
  
  readline = stdin.readline
  
  N, Q = map(int, readline().split())
  A = list(map(int, readline().split()))
  
  st = SegmentTree(N - 1, max, -1)
  st.build(A)
  
  result = []
  for _ in range(Q):
      q = readline()
      if q[0] in "13":
          T, X, V = map(int, q.split())
          if T == 1:
              st.update(X - 1, V)
          elif T == 3:
              ok = N + 1
              ng = X - 1
              while abs(ng - ok) > 1:
                  m = (ok + ng) // 2
                  if st.query(0, m) > V:
                      ok = m
                  else:
                      ng = m
              result.append(ok)
      elif q[0] == "2":
          T, L, R = map(int, q.split())
          result.append(st.query(L - 1, R))
  print(*result, sep="\n")
  
problem_description: Statement
  
  You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries
  of the following types.
  
  The type of i-th query is represented by T_i.
  
    * T_i=1: You are given two integers X_i,V_i. Replace the value of A_{X_i} with V_i.
    * T_i=2: You are given two integers L_i,R_i. Calculate the maximum value among A_{L_i},A_{L_i+1},\cdots,A_{R_i}.
    * T_i=3: You are given two integers X_i,V_i. Calculate the minimum j such that X_i \leq j \leq N, V_i \leq A_j. If there is no such j, answer j=N+1 instead.
samples: [{"input": "5 5\n    1 2 3 2 1\n    2 1 5\n    3 2 3\n    1 3 1\n    2 2 4\n    3 1 3", "output": "3\n    3\n    2\n    6\n    \n\n  * First query: Print 3, which is the maximum of (A_1,A_2,A_3,A_4,A_5)=(1,2,3,2,1).\n  * Second query: Since 3>A_2, j=2 does not satisfy the condition\uff0eSince 3 \\leq A_3, print j=3.\n  * Third query: Replace the value of A_3 with 1. It becomes A=(1,2,1,2,1).\n  * Fourth query: Print 2, which is the maximum of (A_2,A_3,A_4)=(2,1,2).\n  * Fifth query: Since there is no j that satisfies the condition, print j=N+1=6."}]