#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using pbds_tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T>
bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; }
template<typename T>
bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; }

struct io_setup {
	io_setup() {
		ios::sync_with_stdio(false);
		std::cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} io_setup;

int main(){
	ll n,q;
	cin>>n>>q;
	vector<ll> a(n);
	rep(i,0,n) cin>>a.at(i);
	pbds_tree<pair<ll,ll>> st;
	rep(i,0,n){
		st.insert({0,i});
	}
	map<pair<ll,ll>,pair<ll,ll>> mp;
	rep(i,0,n){
		mp[{0,i}]={a.at(i),i};
	}
	rep(Qi,0,q){
		ll t;
		cin>>t;
		if(t==1){
			ll k,x;
			cin>>k>>x;
			k--;
			auto p=*st.find_by_order(k);
			mp[p]={x,p.second};
		}else if(t==2){
			for(auto[p,q]:mp){
				st.erase(p);
				st.insert(q);
			}
			mp.clear();
		}else if(t==3){
			ll k;
			cin>>k;
			k--;
			auto p=*st.find_by_order(k);
			if(mp.count(p)) p=mp.at(p);
			cout<<p.first<<"\n";
		}
	}
}