#include <bits/stdc++.h>

#define int long long

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int32_t main()
{
    int n, q;
    cin >> n >> q;

    vi a(n + 1);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    vi cnt1(n + 1), cnt2(n + 1);
    for (int i = 1; i <= n; ++i)
    {
        if (a[i] == 1)
            cnt1[i] = 1 + cnt1[i - 1];
        else
            cnt1[i] = cnt1[i - 1];

        if (a[i] == 2)
            cnt2[i] = 1 + cnt2[i - 1];
        else
            cnt2[i] = cnt2[i - 1];
    }

    while (q-- > 0)
    {
        int t, xy;
        cin >> t >> xy;

        if (t == 1)
        {
            swap(a[xy], a[xy + 1]);
            if (a[xy] == a[xy + 1])
                continue;
            
            if (a[xy] == 1)
            {
                cnt1[xy]++;
                cnt2[xy]--;
            }
            else
            {
                cnt1[xy]--;
                cnt2[xy]++;
            }
        }
        else
        {
            if (a[xy] == 1)
                cout << cnt1[xy] + min(cnt1[xy - 1], cnt2[n]) << '\n';
            else
                cout << cnt2[xy] + min(cnt2[xy] - 1, cnt1[n]) << '\n';
        }
    }
}