#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
using ll = long long;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int maxn = 1e4 + 5;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, q;
    cin >> n >> q;
    vector <vector <int>> pref(2, vector <int> (n+1));

    vector <int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;

        pref[i+1] = pref[i];
        pref[i+1][a[i]]++;
    }


    for (int att = 0; att < q; att++) {
        int t; cin >> t;

        if (t == 1) {
            int x; cin >> x;
            pref[x][a[x]]++;
            pref[x+1][a[x-1]]--;
            x--;
            swap(a[x], a[x+1]);
        } else {
            int y; cin >> y;
            y--;
            int res = 0;

            if (pref[n][!a[y]] < pref[y+1][a[y]]) {
                cout << pref[n][!a[y]] + pref[y+1][a[y]] << '\n';
            } else {
                res = 2 * pref[y+1][a[y]];
                if (a[0] == a[y]) {
                    res--;
                }

                cout << res << '\n';
            }

        }
    }
}
