class SegTree: def __init__(self, ls, op, e): n = len(ls) self.op = op self.e = e self.size = 1 << (n - 1).bit_length() self.tree = [self.e] * (2 * self.size) for i in range(n): self.tree[self.size + i] = ls[i] for i in range(self.size - 1, 0, -1): self.tree[i] = self.op(self.tree[2 * i], self.tree[2 * i + 1]) def query(self, l, r): res = self.e l += self.size r += self.size while l < r: if l & 1: res = self.op(res, self.tree[l]) l += 1 if r & 1: res = self.op(res, self.tree[r - 1]) l >>= 1 r >>= 1 return res def get(self, k): return self.tree[k + self.size] def set(self, k, x): k += self.size self.tree[k] = x while k > 1: self.tree[k >> 1] = self.op(self.tree[k], self.tree[k ^ 1]) k >>= 1 def __getitem__(self, k): return self.get(k) def __setitem__(self, k, x): self.set(k, x) def chmin(self, k, x): self[k] = min(self[k], x) def chmax(self, k, x): self[k] = max(self[k], x) N, Q = map(int, input().split()) A = list(map(int, input().split())) pos = {a: i for i, a in enumerate(A)} st = SegTree(A, min, 1 << 60) for _ in range(Q): t, l, r = map(int, input().split()) if t == 1: l, r = l - 1, r - 1 st[l], st[r] = st[r], st[l] pos[st[l]], pos[st[r]] = pos[st[r]], pos[st[l]] if t == 2: print(pos[st.query(l - 1, r)] + 1)