#include<bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar_unlocked();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar_unlocked();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar_unlocked();
}
return x * f;
}
inline void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
const int N=1e6+5;
vector<int> a[N],b[N];int p[N],dp[N],n,m;
void outsomebody(int x){
write(x);putchar('\n');
}
void input(){
for(int i=1;i<=n;i++){
int x;
x=read();
a[i].push_back(0);
b[i].push_back(x);
}
}
void choose1(int l,int kkk){
int x;
x=read();
a[l].push_back(kkk);
b[l].push_back(x);
dp[kkk]=l;
}
void choose2(int l,int u){
while(1){
int x=u;
if(x==0){
outsomebody(b[l][0]);
break;
}else if(dp[x]==l){
int v=lower_bound(a[l].begin(),a[l].end(),u)-a[l].begin();
if(v+a[l].begin()==a[l].end()) v--;
outsomebody(b[l][v]);
break;
}else u=p[u];
}
}
void solve(){
for(int kkk=1;kkk<=m;kkk++){
int u,v,l;
u=read();v=read();l=read();
p[kkk]=u;
if(v==1) choose1(l,kkk);
else choose2(l,u);
}
}
void getnm(){
n=read(),m=read();
}
int main(){
getnm();
input();
solve();
return 0;
}