def main(): INT_MAX = 10 ** 6 #与えられる数字の中で最大 MAX_N = 2 * 10 ** 5 + 5 #与えられる要素数の最大 data = [INT_MAX] * (2 * MAX_N - 1) #MAX_Nで初期化 def init(n_): #簡単のため要素数を2のべき乗に n = 1 while n < n_: n *= 2 return n N, Q = map(int, input().split()) n = init(N) def update(k, a): #k番目の値をaに変更 k += n - 1 data[k] = a while k > 0: #登りながら更新 k = (k - 1)//2 data[k] = min(data[k * 2 + 1], data[k * 2 + 2]) def query(a, b, k = 0, l = 0, r = n): if r <= a or b <= l: return INT_MAX if a <= l and r <= b: return data[k] else: vl = query(a, b, k * 2 + 1, l, (l + r)//2) vr = query(a, b, k * 2 + 2, (l + r)//2, r) return min(vl, vr) #初期値の入力 A = list(map(int, input().split())) B = [0] * N for i, a in enumerate(A): data[i + n - 1] = a B[a - 1] = i for i in range(N + n - 1, -1, -2): tmp = i if tmp > 0: tmp = (tmp - 1)//2 data[tmp] = min(data[tmp * 2 + 1], data[tmp * 2 + 2]) #クエリの数 for _ in range(Q): t, l, r = map(int, input().split()) l -= 1 r -= 1 if t == 1: update(l, A[r]) update(r, A[l]) # print ('A[l], A[r]', A[l], A[r]) B[A[l] - 1], B[A[r] - 1] = r, l A[l], A[r] = A[r], A[l] else: tmp = query(l, r + 1) # print (A) # print (B) # print (tmp) # print (A.index(tmp) + 1) print (B[tmp - 1] + 1) if __name__ == '__main__': main()