#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <numeric>

#ifdef LOCAL
#else
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#endif

const long long modul = 998'244'353;

struct SegmentTree {
    struct Node {
        int start;
        int end;

        std::vector<int> min;
    };

    std::vector<Node> tree;

    inline int Get(int v, int l, int r) {
        if (tree[v].start >= l and tree[v].end <= r) {
            return tree[v].min.back();
        }

        if (tree[v].start >= r or tree[v].end <= l) {
            return 1e9;
        }

        return std::min(Get(v * 2 + 1, l, r), Get(v * 2 + 2, l, r));
    }

    inline void Update(int v, int index) {
        if (tree[v].end - tree[v].start == 1) {
            tree[v].min.pop_back();
            if (tree[v].min.size() == 0) {
                tree[v].min.push_back(1e9);
            }

            return;
        }

        int m = (tree[v].start + tree[v].end) / 2;
        if (index < m) {
            Update(v * 2 + 1, index); 
        } else {
            Update(v * 2 + 2, index);
        }

        tree[v].min.back() = std::min(tree[v * 2 + 1].min.back(), tree[v * 2 + 2].min.back());
    }

    void Build(int v, int l, int r, std::vector<std::vector<int>>& vec) {
        tree[v].start = l;
        tree[v].end = r;

        if (r - l == 1) {
            tree[v].min = vec[l];

            std::reverse(tree[v].min.rbegin(), tree[v].min.rend());

            if (tree[v].min.size() == 0) {
                tree[v].min.push_back(1e9);
            }
            return;
        }

        int m = (l + r) / 2;
        Build(v * 2 + 1, l, m, vec);
        Build(v * 2 + 2, m, r, vec);

        tree[v].min.push_back(1);
        tree[v].min.back() = std::min(tree[v * 2 + 1].min.back(), tree[v * 2 + 2].min.back());
    }

    SegmentTree(std::vector<std::vector<int>>& vec) : tree(vec.size() * 4) {
        Build(0, 0, vec.size(), vec);
    }
};

void Solve() {
    int n, q;
    std::cin >> n >> q;

    std::vector<int> vec(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> vec[i];

        --vec[i];
    }

    std::vector<int> res;
    std::vector<bool> used(n);
    std::vector<std::vector<int>> colour(n);

    int type, number;
    for (int i = 0; i < q; ++i) {
        std::cin >> type >> number;
        --number;

        if (type == 1) {
            std::swap(vec[number], vec[number + 1]);
        } else {
            for (int j = 0; j < n; ++j) {
                colour[vec[j]].push_back(j);
            }

            SegmentTree tree(colour);
            tree.Update(0, vec[0]);
            std::vector<int> res;
            res.push_back(0);

            while (res.back() != number) {
                int min = std::min(tree.Get(0, 0, vec[res.back()]), tree.Get(0, vec[res.back()] + 1, n));
                if (min == 1e9) {
                    min = tree.Get(0, vec[res.back()], vec[res.back()] + 1);
                }

                res.push_back(min);
                tree.Update(0, vec[min]);
            }

            std::cout << res.size() << '\n';
            for (int j = 0; j < n; ++j) {
                colour[j].clear();
            }
        }
    }

}

int main() {
    #ifdef LOCAL
        std::cout << '\n';
    #else
        std::ios_base::sync_with_stdio(false);
        std::cin.tie(nullptr);
    #endif

    int t = 1;
    //std::cin >> t;

    for (int i = 0; i < t; ++i) {
        Solve();
    }
}