#pragma gcc optimize("Ofast")
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <random>
#include <bitset>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;
#define int long long
using ll = long long;
using ld = long double;

#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...)
#endif

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

    int n, q;
    cin >> n >> q;
    vector<vector<int>> a(2);
    vector<pair<int, int>> pos(n);
    vector<int> in(n);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        in[i] = x;
        pos[i] = {x - 1, a[x - 1].size()};
        a[x - 1].push_back(i);
    }
    for (int iter = 0; iter < q; iter++) {
        int type;
        cin >> type;
        if (type == 1) {
            int ind;
            cin >> ind;
            ind--;
            if (in[ind] == in[ind + 1]) continue;
            swap(in[ind], in[ind + 1]);
            auto [t1, ind1] = pos[ind];
            auto [t2, ind2] = pos[ind + 1];
            a[t1][ind1] = ind + 1;
            a[t2][ind2] = ind + 2;
        } else {
            int ind;
            cin >> ind;
            ind--;
            auto [t, ans] = pos[ind];
            dbg(t, ans);
            dbg(a);
            dbg(in);
            if (in[0] - 1 == t) {
                ans += min((ll) a[t ^ 1].size(), ans);
            } else {
                ans += min((ll) a[t ^ 1].size(), ans + 1);
            }
            cout << ans + 1 << '\n';
        }
    }
}