import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int q = sc.nextInt(); SegmentTree st = new SegmentTree(n); for (int i = 0; i < n; i++) { st.update(i, sc.nextInt()); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int type = sc.nextInt(); int x = sc.nextInt() - 1; int y = sc.nextInt() - 1; if (type == 1) { int ax = st.get(x); int ay = st.get(y); st.update(x, ay); st.update(y, ax); } else { sb.append(st.query(x, y) + 1).append("\n"); } } System.out.print(sb); } } class SegmentTree { int size; int base; int[] tree; int[] idxes; public SegmentTree(int size) { this.size = size; base = 1; while (base < size) { base <<= 1; } tree = new int[base * 2 - 1]; idxes = new int[base * 2 - 1]; Arrays.fill(tree, Integer.MAX_VALUE); for (int i = 0; i < size; i++) { idxes[i + base - 1] = i; } } public int get(int idx) { return tree[idx + base - 1]; } public void update(int idx, int value) { updateTree(idx + base - 1, value, idx); } private void updateTree(int idx, int value, int min) { tree[idx] = value; idxes[idx] = min; if (idx == 0) { return; } if (idx % 2 == 1) { if (value < tree[idx + 1]) { updateTree((idx - 1) / 2, value, min); } else { updateTree((idx - 1) / 2, tree[idx + 1], idxes[idx + 1]); } } else { if (value < tree[idx - 1]) { updateTree((idx - 1) / 2, value, min); } else { updateTree((idx - 1) / 2, tree[idx - 1], idxes[idx - 1]); } } } public int query(int min, int max) { return idxes[query(min, max, 0, 0, base)]; } public int query(int min, int max, int idx, int left, int right) { if (min >= right || max < left) { return -1; } if (min <= left && right - 1 <= max) { return idx; } int x1 = query(min, max, 2 * idx + 1, left, (left + right) / 2); int x2 = query(min, max, 2 * idx + 2, (left + right) / 2, right); if (x1 != -1 && (x2 == -1 || tree[x1] < tree[x2])) { return x1; } else { return x2; } } }