#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 300000
#define BASE 1200
#define block(x) ((x)/BASE+1)
int n,m,x,y,opt,ttmp,tot,clk,cnt;
int fa[N],deep[N],size[N],pos[N],head[N],l[N],r[N],top[N],f[N];
int a[N],b[N],last[N],xx[N],yy[N],op[N],ans[N],t[N];
bool vis[N];
struct edge{int v,nxt;}e[N];
struct modify{int x,y,z;}mdy[N];
struct query{int i,j,k,lca,ID;}qry[N];
bool cmp(query x,query y){
if (block(x.i)!=block(y.i)) return block(x.i)<block(y.i);
if (block(x.j)!=block(y.j)) return block(x.j)<block(y.j);
return x.k<y.k;
}
void add(int x,int y){e[++tot].v=y; e[tot].nxt=head[x]; head[x]=tot;}
void dfs1(int u){
if (!fa[u]) fa[u]=u; deep[u]=deep[fa[u]]+1; size[u]=1;
l[u]=++ttmp; pos[ttmp]=u;
for (int i=head[u],v;i;i=e[i].nxt)
if ((v=e[i].v)!=fa[u]){fa[v]=u; dfs1(v); size[u]+=size[v];}
r[u]=++ttmp; pos[ttmp]=u;
}
void dfs2(int u){
if (!top[u]) top[u]=u; int t=0;
for (int i=head[u],v;i;i=e[i].nxt) if ((v=e[i].v)!=fa[u] && size[v]>size[t]) t=v;
if (!t) return; top[t]=top[u]; dfs2(t);
for (int i=head[u];i;i=e[i].nxt) if (e[i].v!=fa[u] && e[i].v!=t) dfs2(e[i].v);
}
int lca(int u,int v){
for (;top[u]!=top[v];u=fa[top[u]]) if (deep[top[u]]<deep[top[v]]) swap(u,v);
return deep[u]<deep[v]?u:v;
}
void inc(int x){
vis[x]^=1; if (a[x]>n) return;
if (vis[x]){if (!f[a[x]]) b[block(a[x])]++; f[a[x]]++;}
else{f[a[x]]--; if (!f[a[x]]) b[block(a[x])]--;}
}
void change(int x,int y){
if (vis[x]){inc(x); a[x]=y; inc(x);} else a[x]=y;
return;
}
int solve(){
for (int i=1;;i++)
if (b[i]!=BASE)
for (int j=(i-1)*BASE;j<i*BASE;j++) if (!f[j]) return j;
return -1;
}
int main(){
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++){scanf("%d",&a[i]); last[i]=a[i];}
for (int i=1;i<n;i++){scanf("%d%d",&x,&y); add(x,y); add(y,x);}
for (int i=1;i<=m;i++)scanf("%d%d%d",&op[i],&xx[i],&yy[i]);
dfs1(1); dfs2(1);
for (int i=1;i<=m;i++){
opt=op[i]; x=xx[i]; y=yy[i];
if (opt==0){mdy[++clk]=(modify){x,last[x],y}; last[x]=y;}
if (opt==1){
if (l[x]>l[y]) swap(x,y);
int LCA=lca(x,y);
if (LCA==x) qry[++cnt]=(query){l[x],l[y],clk,0,cnt};
else qry[++cnt]=(query){r[x],l[y],clk,LCA,cnt};
}
}
sort(qry+1,qry+cnt+1,cmp);
for (int i=1,j=0,k=0,xb=1;xb<=cnt;xb++){
while (k<qry[xb].k){k++; change(mdy[k].x,mdy[k].z);}
while (k>qry[xb].k){change(mdy[k].x,mdy[k].y); k--;}
while (i>qry[xb].i) inc(pos[--i]);
while (j<qry[xb].j) inc(pos[++j]);
while (i<qry[xb].i) inc(pos[i++]);
while (j>qry[xb].j) inc(pos[j--]);
if (qry[xb].lca) inc(qry[xb].lca);
ans[qry[xb].ID]=solve();
if (qry[xb].lca) inc(qry[xb].lca);
}
for (int i=1;i<=cnt;i++) printf("%d\n",ans[i]);
return 0;
}