def func(x,y): return min(x,y) class SegmentTree: def __init__(self, n): #a1, a2, ..., an n_ = 1 while n_ < n: n_ *= 2 self.n = n_ self.arr = [10**6] * (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] = func(self.arr[2*k+1], self.arr[2*k+2]) def query(self, l, r):#[l,r)の値を返す L, R = l+self.n, r+self.n ide_ele = 10**6 #単位元(ide_ele)は、区間外の値などに設定する値です。 #ex) 最小値のセグ木 → +inf # 和のセグ木 → 0 # 積のセグ木 → 1 # gcdのセグ木 → 0 res = ide_ele while L < R: if R & 1: R -= 1 res = func(res, self.arr[R-1]) if L & 1: res = func(res, self.arr[L-1]) L += 1 L >>= 1 R >>= 1 return res n,q=map(int,input().split()) a=list(map(int,input().split())) sg=SegmentTree(n) for i in range(1,n+1): sg.update(i,a[i-1]) from collections import defaultdict d=defaultdict(int) for i in range(n): d[a[i]]=i+1 for _ in range(q): k,l,r=map(int,input().split()) if k==1: sg.update(l,a[r-1]) sg.update(r,a[l-1]) d[a[l-1]],d[a[r-1]]=d[a[r-1]],d[a[l-1]] a[l-1],a[r-1]=a[r-1],a[l-1] else: print(d[sg.query(l,r+1)])