//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
#define int long long
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2")

constexpr int mod = 998244353;
int st(int x,int n)
{
    if (n==0) return x%mod;
    int a = st(x,n-1);
    return ((a*a)%mod+mod)%mod;
}
int get_st(int x,int n)
{
    int ans=1;
    for (int i=30;i>=0;i--)
    {
        if ((1<<i)<=n)
        {
            int a = st(x,i);
            n -= (1<<i);
            ans = ((ans*a)%mod+mod)%mod;
        }
    }
    return ans;
}
vector<int> ans,v;
vector<int> d;
void build(int ind,int l,int r)
{
    if (r-l==1)
    {
        d[ind] = (v[l]==1);
        return;
    }
    int m = (r+l)/2;
    build(2*ind+1,l,m);
    build(2*ind+2,m,r);
    d[ind] = d[2*ind+1]+d[2*ind+2];
}
void update(int ind,int l,int r,int i,int x)
{
    if (i>=r||i<l) return;
    if (r-l==1)
    {
        d[ind] = (x==1);
        return;
    }
    int m = (r+l)/2;
    update(2*ind+1,l,m,i,x);
    update(2*ind+2,m,r,i,x);
    d[ind] = d[2*ind+1]+d[2*ind+2];
}
int get(int ind,int l,int r,int ql,int qr)
{
    if (l>=qr||r<=ql) return 0;
    if (l>=ql&&r<=qr) return d[ind];
    int m = (r+l)/2;
    return get(2*ind+1,l,m,ql,qr)+get(2*ind+2,m,r,ql,qr);
}
signed main()
{
    int n,q;
    cin >> n >> q;
    v.resize(n);
    ans.resize(n);
    d.resize(4*n);
    for (int i=0;i<n;i++) cin >> v[i];
    for (int i=0;i<n;i++) v[i]--;
    vector<int> v1,v2;
    for (int i=0;i<n;i++)
    {
        if (v[i]==1) v1.push_back(i);
        if (v[i]==2) v2.push_back(i);
    }
    for (int i=0;i<n;i++)
    {
        if (v[i]==1)
        {
            ans[i] = lower_bound(v1.begin(),v1.end(),i)-v1.begin();
        }
        else
        {
            ans[i] = lower_bound(v2.begin(),v2.end(),i)-v2.begin();
        }
    }
    int c1 = v1.size(),c2 = v2.size();
    build(0,0,n);
    for (int i=0;i<q;i++)
    {
        int t;
        cin >> t;
        if (t==1)
        {
            int x;
            cin >> x;
            x--;
            swap(v[x],v[x+1]);
            update(0,0,n,x,v[x]);
            update(0,0,n,x+1,v[x+1]);
        }
        if (t==2)
        {
            int y;
            cin >> y;
            y--;
            int e = get(0,0,n,0,y);
            int dv = y-e;
            if (v[y]==1)
            {
                if (v[0]==1)
                {
                    cout << e+min(e,c2)+1 << "\n";
                }
                else
                {
                    cout << e+min(e+1,c2)+1 << "\n";
                }
            }
            else
            {
                if (v[0]==1)
                {
                    cout << dv+min(dv+1,c1)+1 << "\n";
                }
                else
                {
                    cout << dv+min(dv,c1)+1 << "\n";
                }
            }
        }
    }
}
