import sys input=sys.stdin.readline class SegmentTree: def __init__(self, n): #a1, a2, ..., an n_ = 1 while n_ < n: n_ *= 2 self.n = n_ self.arr = [10**18] * (2*self.n-1) def update(self, k, a): #0_indexed k += self.n - 1 self.arr[k] = a while k > 0: k = (k-1) // 2 self.arr[k] = min(self.arr[2*k+1], self.arr[2*k+2]) def query(self, l, r): #min(a[l:r)) L, R = l+self.n, r+self.n ide_ele = float("inf") res = ide_ele while L < R: if R & 1: R -= 1 res = min(res, self.arr[R-1]) if L & 1: res = min(res, self.arr[L-1]) L += 1 L >>= 1 R >>= 1 return res from collections import defaultdict n,q=map(int,input().split()) a=list(map(int,input().split())) st=SegmentTree(n) idx=defaultdict(int) for i in range(n): st.update(i,a[i]) idx[a[i]]=i for _ in range(q): i,l,r=map(int,input().split()) if i==1: st.update(l-1,a[r-1]) st.update(r-1,a[l-1]) idx[a[r-1]]=l-1 idx[a[l-1]]=r-1 a[l-1],a[r-1]=a[r-1],a[l-1] else: x=st.query(l-1,r) print(idx[x]+1)