#include using namespace std; template struct monoid { using F = function; T e; F f; monoid(T e, F f) : e(e), f(f) { } }; template struct segment_tree : monoid { using F = function; int n; vector tree; segment_tree(int n_, T e, F f) : monoid(e, f) { for (n = 1; n <= n_;) { n *= 2; } tree.assign(2 * n, monoid::e); } segment_tree(int n_, vector &init, T e, F f) : monoid(e, f) { for (n = 1; n < n_;) { n *= 2; } tree.assign(2 * n, monoid::e); for (size_t i = 0; i < init.size(); i++) { update(i, init[i]); } } void update(int index, T x) { index += n; tree[index] = x; for (index /= 2; 0 < index; index /= 2) { tree[index] = monoid::f(tree[2 * index + 0], tree[2 * index + 1]); } } T query(int index, int il, int ir, int l, int r) { if (ir <= l || r <= il) { return monoid::e; } if (il <= l && r <= ir) { return tree[index]; } else { T left = query(2 * index + 0, il, (il + ir) / 2, l, r); T right = query(2 * index + 1, (il + ir) / 2, ir, l, r); return monoid::f(left, right); } } T query(int l, int r) { return query(1, 0, n, l, r); } }; int main() { int n, q; cin >> n >> q; vector as(n); for (auto &&a : as) { cin >> a; a--; } vector mp(n); for (int i = 0; i < n; i++) { mp[as[i]] = i; } segment_tree seg(n, as, (1LL << 60), [](int64_t l, int64_t r) { return min(l, r); }); for (int _ = 0; _ < q; _++) { int t, l, r; cin >> t >> l >> r; l--; r--; if (t == 1) { seg.update(l, as[r]); seg.update(r, as[l]); swap(mp[as[l]], mp[as[r]]); swap(as[l], as[r]); } else if (t == 2) { cout << mp[seg.query(l, r + 1)] + 1 << endl; } } return 0; }