class SegmentTree: def __init__(self, lis, ele, op): self.lis = lis self.len = len(lis) self.n = 1 << ((self.len - 1).bit_length()) self.op = op self.ele = ele self.tree = self._build(lis) def _build(self, lis): res_tree = [self.ele for _ in range(2 * self.n)] for i in range(len(self.lis)): res_tree[self.n + i - 1] = self.lis[i] for i in range(self.n - 2, -1, -1): res_tree[i] = self.op(res_tree[i * 2 + 1], res_tree[i * 2 + 2]) return res_tree def __get__(self, i): return self.tree[self.n + i - 1] def update(self, i, x): i += self.n - 1 self.tree[i] = x while i > 0: i -= 1 i >>= 1 self.tree[i] = self.op(self.tree[i * 2 + 1], self.tree[i * 2 + 2]) def prod(self, l, r): l += self.n - 1 r += self.n - 1 L = self.ele R = self.ele while l < r: if l & 1 == 0: L = self.op(L, self.tree[l]) l += 1 if r & 1 == 0: r -= 1 R = self.op(self.tree[r], R) l -= 1 l >>= 1 r >>= 1 return self.op(L, R) def op(x, y): if x[0] > y[0]: return y else: return x n, q = map(int, input().split()) a = list(map(int, input().split())) b = [(a[i], i + 1) for i in range(n)] ST = SegmentTree(b, (2 ** 64 - 1, None), op) for _ in range(q): op, l, r = map(int, input().split()) if op == 1: al = ST.prod(l - 1, l)[0] ar = ST.prod(r - 1, r)[0] ST.update(l - 1, (ar, l)) ST.update(r - 1, (al, r)) else: print(ST.prod(l - 1, r)[1])