#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <random>
using namespace std;

#define int long long

const int Mx = 1e6 + 10;
int A[Mx];
pair <int, int> Qs[Mx];
bool Used[Mx];
int Prs[Mx][7];
int N, Q;
bool f7 = true;

signed main() {
    cin >> N >> Q;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        if (A[i] > 2) {
            f7 = false;
        }
    }
    if (f7) {
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j < 3; j++) {
                Prs[i][j] = Prs[i-1][j] + (A[i] == j);
                //cout << i << ' ' << j << ' ' << Prs[i][j] << endl;
            }
        }
    }
    for (int i = 0; i < Q; i++) {
        cin >> Qs[i].first >> Qs[i].second;
    }
    for (int I = 0; I < Q; I++) {
        int par = Qs[I].first, x = Qs[I].second;
        if (par == 1) {
            if (A[x] == A[x + 1]) {
                continue;
            }
            swap(A[x], A[x+1]);
            if (f7) {
                for (int i = 1; i <= N; i++) {
                    for (int j = 1; j < 3; j++) {
                        Prs[i][j] = Prs[i-1][j] + (A[i] == j);
                    }
                }
            }
        }
        else {
            int y = x;
            if (f7) {
                int res = max((int)0, min(Prs[y][1], Prs[y][2]) - 1) * 2 + (y != A[1]) + 1;
                cout << res << '\n';
                continue;
            }
            int cur = 1, cnt = 1;
            bool f = false;
            Used[1] = true;
            while (cur != y) {
                if (f) {
                    Used[cur] = true;
                    cnt++;
                    while (Used[cur]) {
                         cur++;
                    }
                    continue;
                }
                f = true;
                for (int i = 1; i <= N; i++) {
                    if (!Used[i] && A[i] != A[cur]) {
                        //cout << "test: " << i << ' ' << A[i] << endl;
                        cur = i;
                        cnt++;
                        Used[i] = true;
                        f = false;
                        break;
                    }
                }
            }
            fill(Used, Used + N + 10, false);
            cout << cnt << '\n';
        }
    }
}

/*
9 4
1 1 1 2 2 1 2 1 2
1 1
1 1
2 5
2 1
*/
