#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#define INF 247483647
#define N 3000100
using namespace std;
int read() {
int rtn = 0;
char ch = getchar();
while (!isdigit(ch))ch = getchar();
while (isdigit(ch))rtn = rtn * 10 + ch - '0', ch = getchar();
return rtn;
}
struct node {
int l, r, w, d, fa;
} heap[N];
int n, m;
int mergef(int x, int y) {
if (!x || !y)return x + y;
if (heap[x].w > heap[y].w || heap[x].w == heap[y].w && x > y)
swap(x, y);
heap[x].r = mergef(y, heap[x].r);
heap[heap[x].r].fa = x;
if (heap[heap[x].l].d < heap[heap[x].r].d)
swap(heap[x].l, heap[x].r);
if (heap[x].r)heap[x].d = heap[heap[x].r].d + 1;
else heap[x].d = 0;
return x;
}
int pop(int x) {
int l = heap[x].l, r = heap[x].r;
heap[x].l = heap[x].r = heap[x].w = -INF;
heap[l].fa = l, heap[r].fa = r;
return heap[x].fa = mergef(l, r);
}
int findf(int x) {
if (heap[x].fa == x)return x;
return heap[x].fa = findf(heap[x].fa);
}
void Insert(int x) {
heap[x].w = read(), heap[x].d = 0, heap[x].fa = x;
}
int main() {
n = read(), m = read();
heap[0].d = -1;
for (int i = 1; i <= n; i++)Insert(i);
while (m--) {
int opt = read();
if (opt == 1) {
int x = read(), y = read();
if (heap[x].w == -INF || heap[y].w == -INF)continue;
int fx = findf(x), fy = findf(y);
if (fx != fy)mergef(fx, fy);
}
if (opt == 2) {
int x = read();
if (heap[x].w == -INF) {
printf("-1\n");
continue;
}
printf("%d\n", heap[findf(x)].w);
pop(findf(x));
}
}
return 0;
}