#include <iostream>
#include <vector>
#include <unordered_set>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#include <random>
#include <algorithm>
#include <unordered_map>

using namespace std;
using ll = long long int;
using ld = long double;
using ull = unsigned long long int;
using uint = unsigned int;

const ll linf = 1e18 + 7;
const int inf = 1e9 + 7;
const ll M = 998244353;
const ld PI = 2 * asin(1);

#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend();
#define nr nullptr

vector <int> a;

struct segtree
{   
    vector <int> tr;
    
    void resize(int n)
    {
        tr.resize(4 * n, 0);
    }

    void build(int l, int r, int v)
    {
        if (l == r - 1)
        {
            if (a[l] == 1) tr[v] = 1; 
            return;
        } 
        int m = (l + r) / 2;
        build(l, m, v * 2 + 1);
        build(m, r, v * 2 + 2);
        tr[v] = tr[v * 2 + 1] + tr[v * 2 + 2];
    }

    void update(int l, int r, int v, int ind, int x)
    {
        if (l == r - 1)
        {
            if (x == 1) tr[v] = 1;
            else tr[v] = 0;
            return;
        }
        int m = (l + r) / 2;
        if (ind < m)
        {
            update(l, m, v * 2 + 1, ind, x);
        }
        else
        {
            update(m, r, v * 2 + 2, ind, x);
        }
        tr[v] = tr[v * 2 + 1] + tr[v * 2 + 2];
    }

    int get(int l, int r, int v, int ql, int qr)
    {
        if (qr <= l || r <= ql) 
        {
            return 0;
        }
        else if (ql <= l && r <= qr)
        {
            return tr[v];
        }
        int m = (l + r) / 2;
        return get(l, m, v * 2 + 1, ql, qr) + get(m, r, v * 2 + 2, ql, qr);
    }

};

segtree tr;

void solve()
{
    int n, q;
    cin >> n >> q;
    a.resize(n);
    for (auto& i : a)
    {
        cin >> i;
    }
    tr.resize(n);
    tr.build(0, n, 0);
    for (int i = 0; i < q; i++)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int x;
            cin >> x;
            x--;
            tr.update(0, n, 0, x, a[x + 1]);
            tr.update(0, n, 0, x + 1, a[x]);
            swap(a[x], a[x + 1]);
        }
        else
        {
            int x;
            cin >> x;
            x--;
            if (a[x] != 1)
            {
                int s = x+1-tr.get(0, n, 0, 0, x+1);
                int p = tr.get(0, n, 0, 0, x + 1);
                if (s > p)
                {
                    cout << p * 2 + s - p;
                }
                else
                {
                    cout << s * 2;
                }
                cout << '\n';
            }
            else
            {
                int t = x+1 - tr.get(0, n, 0, 0, x+1);
                int p = tr.get(0, n, 0, 0, x + 1);
                int al = n - tr.get(0, n, 0, 0, n);
                if (p > al)
                {
                    cout << al * 2 + p - al;
                }
                else if (p > t)
                {
                    cout << t * 2 + p - t;
                }
                else
                {
                    cout << 2 * (p - 1) + t - p + 2;
                }
                cout << '\n';
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //freopen("input.txt", "r", stdin);

    int _ = 1;
    while (_--)
    {
        solve();
        cout << '\n';
    }
}
