#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cstring>
#include <string>

#define maxlog 19
#define maxdim 100005

using namespace std;

int n, op, root;
int P[maxlog][maxdim], niv[maxdim];
vector<int> G[maxdim];

void dfs(int nod) {
	niv[nod] = niv[P[0][nod]] + 1;

	for (int son : G[nod]) {
		if (son == P[0][nod]) {
			continue;
		}
		P[0][son] = nod;
		dfs(son);
	}
}

inline int lca(int x, int y) {

	if (niv[x] < niv[y]) {
		swap(x, y);
	}

	int log1, log2;
	for(log1 = 1; (1 << log1) < niv[x]; ++log1);
	for(log2 = 1; (1 << log2) < niv[y]; ++log2);

	for (int p = log1; p >= 0; --p) {
		if (niv[x] - (1<<p) >= niv[y]) {
			x = P[p][x];
		}
	}

	if (x == y) {
		return x;
	}

	for (int p = log2; p >= 0; --p) {
		if (P[p][x] && P[p][x] != P[p][y]) {
			x = P[p][x];
			y = P[p][y];
		}
	}

	return P[0][x];
}

inline int dist(int x, int y) {
	return niv[x] + niv[y] - 2 * niv[lca(x, y)];
}

inline int solve(int x, int y) {

	int lca_node = lca(x, y);
	int sol = -1;
	int x_init = x, y_init = y;

	if (x == y) {
		return -1;
	}
	// printf("%d %d au lca %d\n", x, y, lca_node);
	if (x != lca_node) {
		for (int p = 18; p >= 0; --p) {
			if (P[p][x] && niv[P[p][x]] > niv[lca_node]) {
				if (dist(root, P[p][x]) > dist(root, P[0][P[p][x]])) {
					x = P[p][x];
				}
			}
		}
	}
	if (y != lca_node) {
		for (int p = 18; p >= 0; --p) {
			if (P[p][y] && niv[P[p][y]] > niv[lca_node]) {
				if (dist(root, P[p][y]) > dist(root, P[0][P[p][y]])) {
					y = P[p][y];
				}
			}
		}
	}
	// printf("%d %d---\n", x, y);
	if ((P[0][x] == lca_node && y != lca_node) || x == lca_node) {
		return P[0][y] == x_init ? -1 : P[0][y];
	}
	return P[0][x] == y_init ? -1 : P[0][x];
}

int main() {

	#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	scanf("%d %d", &n, &op);
	for (int i = 1; i < n; ++i) {
		int x, y;
		scanf("%d %d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}

	dfs(1);
	for (int p = 1; (1<<p) < n; ++p) {
		for (int i = 1; i <= n; ++i) {
			P[p][i] = P[p-1][P[p-1][i]];
		}
	}

	while (op--) {
		int type;
		scanf("%d", &type);
		if (type == 1) {
			scanf("%d", &root);
			continue;
		}

		int x, y;
		scanf("%d %d", &x, &y);
		printf("%d\n", solve(x, y));
	}

	return 0;
}