import sys import numpy as np N,Q = map(int,sys.stdin.readline().split()) INF = 10**6 size = 300 data = np.full(N+(-N)%size,INF,dtype=np.int32) data[:N] = np.array(sys.stdin.readline().split(),dtype=np.int32) query = [tuple(int(x)-1 for x in row.split()) for row in sys.stdin.readlines()] x_to_i = [None] * (N+1) for i,x in enumerate(data[:N]): x_to_i[x] = i N += (-N)%size Nbucket = N//size bucket = np.array([data[i*size:(i+1)*size].min() for i in range(Nbucket)]) def RmQ(L,R): R += 1 nL = L//size nR = R//size if nL == nR: return data[L:R].min() x = data[L:(nL+1)*size].min() if R%size != 0: x = min(x,data[nR*size:R].min()) if nL+1 < nR: x = min(x,bucket[nL+1:nR].min()) return x for q,L,R in query: if q == 0: x,y = data[L],data[R] data[L] = y; data[R] = x iL = L//size; iR = R//size bucket[iL] = data[iL*size:iL*size+size].min() bucket[iR] = data[iR*size:iR*size+size].min() x_to_i[y] = L x_to_i[x] = R elif q == 1: print(x_to_i[RmQ(L,R)]+1)