#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi")

using namespace std;
// using namespace __gnu_pbds;
// template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve();

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    int t = 1;
    while (t--) {
        solve();
    }
}

#define int long long
const int MAXN = 1e6 + 1, MOD = 998244353, INF = 2e18;


void solve() {
    int n,q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    while (q--) {
        int z;
        cin >> z;
        if (z == 1) {
            int l;
            cin >> l;
            l--;
            swap(a[l], a[l+1]);
        } else {
            vector<pair<int,int>> vec;
            int last = 0;
            for (int i = 1; i < n; i++) {
                if (a[i] == a[i-1]) {
                    continue;
                } else {
                    vec.push_back({last, i-1});
                    last = i;
                }
            }
            vec.push_back({last, n-1});
            int y;
            cin >> y;
            y--;
            if (vec.size() == 1) {
                cout << y + 1 << '\n';
                continue;
            }
            int i1 = 0, i2 = 1;
            int now = 0;
            bool f = 0;
            while (true) {
                int ln1 = vec[i1].second-vec[i1].first+1;
                int ln2 = vec[i2].second-vec[i2].first + 1;
                if (y >= vec[i1].first && y <= vec[i1].second && min(ln1, ln2) >= y-vec[i1].first + 1) {
                    if (!f) {
                        now += (y-vec[i1].first) * 2 + 1;
                    } else {
                        now += (y-vec[i1].first+1) * 2;
                    }
                    break;
                } else if (y >= vec[i2].first && y <= vec[i2].second && min(ln1, ln2) >= y-vec[i2].first + 1) {
                    if (!f) {
                        now += (y-vec[i2].first + 1) * 2;
                    } else {
                        now += (y-vec[i2].first) * 2 + 1;
                    }
                    break;
                } else {
                    if (ln1 <= ln2) {
                        now += ln1 * 2;
                        vec[i2].first += ln1;
                        i1 = i2;
                        i2 = i1 + 1;
                        f ^= 1;
                    } else {
                        now += ln2 * 2;
                        vec[i1].first += ln2;
                        i2++;
                    }
                    if (vec[i1].first > vec[i1].second) {
                        i1 = i2;
                        i2++;
                        f=0;
                    }
                    if (i2 == vec.size()) {
                        now += y-vec[i1].first+1;
                        break;
                    }
                }
            }
            cout << now << '\n';
        }
    }
}
