import sys input = sys.stdin.buffer.readline class SegmentTree: """ https://qiita.com/dn6049949/items/afa12d5d079f518de368 から拝借しています。 """ def __init__(self, size, f=lambda x, y: min(x, y), default=10 ** 6): self.size = 2 ** (size - 1).bit_length() self.default = default self.dat = [default] * (self.size * 2) self.f = f def initialize(self, A): for i, a in enumerate(A, self.size): self.dat[i] = a for i in range(self.size - 1, 0, -1): self.dat[i] = self.f(self.dat[i * 2], self.dat[i * 2 + 1]) def update(self, i, x): i += self.size self.dat[i] = x while i > 0: i >>= 1 self.dat[i] = self.f(self.dat[i * 2], self.dat[i * 2 + 1]) def query(self, l, r): """半開区間[l,r)""" l += self.size r += self.size lres, rres = self.default, self.default while l < r: if l & 1: lres = self.f(lres, self.dat[l]) l += 1 if r & 1: r -= 1 rres = self.f(self.dat[r], rres) l >>= 1 r >>= 1 res = self.f(lres, rres) return res N, Q = map(int, input().split()) A = list(map(int, input().split())) indices = [0] * (N + 1) for i, a in enumerate(A): indices[a] = i seg = SegmentTree(N) seg.initialize(A) for _ in range(Q): q, *lr = map(int, input().split()) if q == 1: l, r = lr l -= 1 r -= 1 al, ar = A[l], A[r] A[r], A[l] = al, ar indices[ar], indices[al] = l, r seg.update(r, al) seg.update(l, ar) else: # q=2 l, r = lr print(indices[seg.query(l - 1, r)] + 1)