#!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools import bisect import heapq def input(): return sys.stdin.readline()[:-1] # sys.setrecursionlimit(1000000) # _INPUT = """3 3 # 2 1 3 # 2 1 3 # 1 2 3 # 2 1 3 # """ # sys.stdin = io.StringIO(_INPUT) INF = 10**10 class SegTree_Update_QRMin: def __init__(self, a) -> None: n = len(a) self.N0 = 1 << (n-1).bit_length() self.data = ([2**31-1] * self.N0) + a + ([2**31-1] * (self.N0-n)) for i in reversed(range(1, self.N0)): self.data[i] = min(self.data[i*2], self.data[i*2+1]) def update(self, i, x): i += self.N0 self.data[i] = x while i > 0: i >>= 1 self.data[i] = min(self.data[i*2], self.data[i*2+1]) def query_rmin(self, l, r): l += self.N0 r += self.N0 s = 2**31-1 while l < r: if l & 1: s = min(s, self.data[l]) l += 1 if r & 1: s = min(s, self.data[r-1]) r -= 1 l >>= 1 r >>= 1 return s def get_value(self, i): return self.data[i+self.N0] N, Q = map(int, input().split()) A = list(map(lambda x: int(x)-1, input().split())) seg_tree = SegTree_Update_QRMin(A) T = [0] * N for i, a in enumerate(A): T[a] = i for _ in range(Q): i, l, r = map(int, input().split()) l -= 1 r -= 1 if i == 1: v_l = seg_tree.get_value(l) v_r = seg_tree.get_value(r) seg_tree.update(l, v_r) seg_tree.update(r, v_l) T[v_l] = r T[v_r] = l else: m = seg_tree.query_rmin(l, r+1) ans = T[m] + 1 print(ans)