#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<climits>
#include<vector>
#include<set>
#include<map>
#include<deque>
#include <unordered_map>
#include<unordered_set>
#include<unordered_set>

#define int long long
using namespace std;

void simulate(vector<int>& a, vector<int>& order, vector<int>& place) {
    order = {1};
    place[1] = 1;
    set<pair<int, int>> st;
    for (int i = 2; i<a.size(); ++i) {
        st.insert({i, a[i]});
    }
    while (!st.empty()) {
        auto iter = st.begin();
        for (; (iter!=st.end()) && (iter->second == a[order.back()]); ++iter) {
            int i = iter->first;
            int ai = iter->second;
            int bp = 0;
        }
        if (iter == st.end())
            iter = st.begin();
        order.push_back(iter->first);
        place[iter->first] = order.size();
        st.erase(iter);
    }
}

void simulateClever(vector<int>& a, vector<int>& order, vector<int>& place) {
    order = {1};
    place[1] = 1;
    vector<int> v;
    for (int i = a.size()-1; i>=2; --i) v.push_back(i);
    int dt = -1;
    deque<int> delayed;//indexes
    while (v.size() + delayed.size()) {
        if (dt!=-1) {
            if ((a[order.back()] != dt) || v.empty()) {//забрать из отложеных
                order.push_back(delayed.front());
                place[delayed.front()] = order.size();
                delayed.pop_front();
                if (delayed.empty())
                    dt = -1;
                continue;
            }
        }
        if (a[order.back()] == a[v.back()]) {//поместить  отложенные
            dt = a[v.back()];
            delayed.push_back(a.size() - v.size());
        }
        else {//забрать из общего
            order.push_back(a.size()-v.size());
            place[a.size()-v.size()] = order.size();
        }
        v.pop_back();
    }
    int bp = 0;
}

void solve() {
    int n, q; cin >> n >> q;
    vector<int> a(n+1), order, place(n+1), res;
    for(int i = 1; i<=n; ++i) cin >> a[i];
    if (n*q<=1) {
        simulateClever(a, order, place);
        for (int k = 0; k<q; ++k) {
            int t; cin >> t;
            if (t == 1) {
                int xi; cin >> xi;
                if (a[xi] == a[xi+1]) continue;
                swap(a[xi], a[xi+1]);
                simulateClever(a, order, place);
            }
            else {
                int yi; cin >> yi;
                res.push_back(place[yi]);
            }
        }
    }
    else {
        bool oddodd = (a[1] == 1);
        unordered_map<int, int> oddmp, evenmp;//сколько 2 до 2 или 1 до 1 с индексом х
        int odd = 0, even = 0;
        for (int i = 1; i<=n; ++i) {
            if (a[i]==1) {
                oddmp[i] = odd;
                ++odd;
            }
            else {
                evenmp[i] = even;
                ++even;
            }
        }
        for (int k = 0; k<q; ++k) {
            int t; cin >> t;
            if (t == 1) {
                int xi; cin >> xi;
                if (a[xi] == a[xi+1]) continue;
                if(a[xi] == 1) {
                    oddmp[xi+1] = oddmp[xi];
                    oddmp[xi] = 0;
                    evenmp[xi] = evenmp[xi+1];
                    evenmp[xi+1] = 0;
                }
                else {
                    evenmp[xi+1] = evenmp[xi];
                    evenmp[xi] = 0;

                    oddmp[xi] = oddmp[xi+1];
                    oddmp[xi+1] = 0;
                }
                swap(a[xi], a[xi+1]);
                oddodd = (a[1] == 1);
            }
            else {
                int yi; cin >> yi;
                if (a[yi] == 1) {
                    if (oddodd)
                        res.push_back(1 + oddmp[yi]*2);
                    else
                        res.push_back(2 + oddmp[yi]*2);
                }
                else {
                    if (oddodd)
                        res.push_back(2+evenmp[yi]*2);
                    else
                        res.push_back(1+evenmp[yi]*2);
                }
            }
        }
    }


    for (int r : res) cout << r << "\n";
}


signed main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();
    return 0;
}