#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 ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using pii = pair<int, int>;


void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> cnt1(n), cnt2(n);
    cnt1[0] = (a[0] == 1);
    cnt2[0] = (a[0] == 2);

    for (int i = 1; i < n; i++) {
        cnt1[i] = cnt1[i - 1] + (a[i] == 1);
        cnt2[i] = cnt2[i - 1] + (a[i] == 2);
    }

    while (q--) {
        int t; cin >> t;
        if (t == 1) {
            int i; cin >> i;
            if (a[i - 1] == 1 && a[i] == 2) {
                cnt1[i - 1]--;
                cnt2[i - 1]++; 
            } else if (a[i - 1] == 2 && a[i] == 1){
                cnt1[i - 1]++;
                cnt2[i - 1]--; 
            }
            swap(a[i - 1], a[i]);
        } else {
            int y; cin >> y; y--;
            int c1 = cnt1[y];
            int c2 = cnt2[y];
            if (a[0] == 1 && a[y] == 1) {
                cout << min(cnt2.back(), c1 - 1) + c1 << "\n";
            } else if (a[0] == 2 && a[y] == 2) {
                cout << min(cnt1.back(), c2 - 1) + c2 << "\n";
            } else if (a[y] == 1) {
                cout << min(cnt2.back(), c1) + c1 << "\n";
            } else {
                cout << min(cnt1.back(), c2) + c2 << "\n";

            }
                
        }
    }
}



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

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }

}