//#define NDEBUG
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using ll = long long;

using std::vector;
using std::make_pair;
using std::pair;

struct bit {
    std::vector<int> t;

    bit(int n) : t(n + 1) {}

    void add(int i, int x) {
        for (++i; i < t.size(); i += i & -i) {
            t[i] += x;
        }
    }

    int sum(int i) {
        int res = 0;
        for (; i > 0; i -= i & -i) {
            res += t[i];
        }
        return res;
    }

    int sum(int l, int r) {
        return sum(r) - sum(l);
    }
};

void solve() {
    int n, q;
    std::cin >> n >> q;
    std::vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
        --a[i];
    }
    int tp;
    bit cnt0(n);
    for (int i = 0; i < n; ++i) {
        cnt0.add(i, a[i] != 0);
    }
    std::vector<int> balance(n);
    balance[0] = (a[0] == 0 ? 1 : 0);
    for (int i = 1; i < n; ++i) {
        if (a[i] == 0) {
            balance[i] = balance[i - 1] + 1;
        } else {
            balance[i] = std::max(0, balance[i - 1] - 1);
        }
    }


    for (int i = 0; i < q; ++i) {
        std::cin >> tp;
        if (tp == 1) {
            int xi;
            std::cin >> xi;
            --xi;
            if ((a[xi] != 0) ^ (a[xi + 1] != 0)) {

            }
            cnt0.add(xi, -(a[xi] != 0));
            cnt0.add(xi + 1, -(a[xi + 1] != 0));
            std::swap(a[xi], a[xi + 1]);
            cnt0.add(xi, (a[xi] != 0));
            cnt0.add(xi + 1, (a[xi + 1] != 0));

            balance[0] = (a[0] == 0 ? 1 : 0);
            for (int j = 1; j < n; ++j) {
                if (a[j] == 0) {
                    balance[j] = balance[j - 1] + 1;
                } else {
                    balance[j] = std::max(0, balance[j - 1] - 1);
                }
            }

        } else {
            int yi;
            std::cin >> yi;
            --yi;
            if (a[yi] != 0) {
                std::cout << yi - balance[yi] + 1 << '\n';
            } else {
                if (yi == 0) {
                    std::cout << 1 << '\n';
                    continue;
                }
                std::cout << yi + std::min(balance[yi - 1], cnt0.sum(yi, n)) + 1 << '\n';
            }
        }
    }

}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
}

