#include <bits/stdc++.h>

using namespace std;

vector<int> segTree;

void modify(int i,int x,int l,int r,int indV)
{
    if(l > i || r < i)
        return ;
    else if(l == r)
    {
        segTree[indV] += x;
        return ;
    }
    int m = (l+r)/2;
    modify(i,x,l,m,indV*2+1);
    modify(i,x,m+1,r,indV*2+2);
    segTree[indV] = segTree[indV*2+1] + segTree[indV*2+2];
    return ;
}

int get(int lx,int rx,int l,int r,int indV)
{
    if(l > rx || r < lx)
        return 0;
    else if(l >= lx && r <= rx)
        return segTree[indV];
    int m = (l+r)/2;
    int sl = get(lx,rx,l,m,indV*2+1);
    int sr = get(lx,rx,m+1,r,indV*2+2);
    return sl + sr; 
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,q;
    cin >> n >> q;
    segTree.resize(4 * n);
    int a[n];
    for(int i = 0;i < n;++i)
    {
        cin >> a[i];
        if(a[i] == 1)
        {
            modify(i,1,0,n-1,0);
        }
    }
    while(q--)
    {
        int t;
        cin >> t;
        if(t == 1)
        {
            int x;
            cin >> x;
            x--;
            if(a[x] != a[x+1])
            {
                if(a[x] == 1)
                {
                    modify(x,-1,0,n-1,0);
                    modify(x+1,1,0,n-1,0);
                }
                else
                {
                    modify(x,1,0,n-1,0);
                    modify(x+1,-1,0,n-1,0);
                }
            }
            swap(a[x],a[x+1]);
        }
        else
        {
            int y;
            cin >> y;
            y--;
            if(a[y] == 1)
            {
                cout << get(0,y-1,0,n-1,0) * 2 + (a[0] == 2) << "\n";
            }
            else
            {
                cout << (y-get(0,y-1,0,n-1,0)) * 2 + (a[0] == 1) << "\n";
            }
        }
    }
}