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

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

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;
    std::vector<int> cnt0(n + 1);
    for (int i = 0; i < n; ++i) {
        cnt0[i + 1] = cnt0[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);
        }
    }


    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)) {

            }
            std::swap(a[xi], a[xi + 1]);
            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);
                }
            }
            for (int i = 0; i < n; ++i) {
                cnt0[i + 1] = cnt0[i] + (a[i] != 0);
            }
        } else {
            int yi;
            std::cin >> yi;
            --yi;
            if (a[yi] != 0) {
                int ans = yi;
                int mx = 0;
                int cur = 0;
                for (int j = yi - 1; j >= 0; --j) {
                    if (a[j] == 0) {
                        ++cur;
                    } else {
                        --cur;
                    }
                    mx = std::max(mx, cur - 1);
                }
                std::cout << ans - mx + 1 << '\n';
            } else {
                if (yi == 0) {
                    std::cout << 1 << '\n';
                    continue;
                }
                std::cout << yi + std::min(balance[yi - 1], cnt0[n] - cnt0[yi]) + 1 << '\n';
            }
        }
    }

}

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

