Xenia the programmer has a tree consisting of n nodes. We will consider the tree nodes indexed from 1 to n. We will also consider the first node to be initially painted red, and the other nodes — to be painted blue.

The distance between two tree nodes v and u is the number of edges in the shortest path between v and u.

Xenia needs to learn how to quickly execute queries of two types:

  1. paint a specified blue node in red; 
  2. calculate which red node is the closest to the given one and print the shortest distance to the closest red node. 



Your task is to write a program which will execute the described queries.

Input

The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of nodes in the tree and the number of queries. Next n - 1 lines contain the tree edges, the i-th line contains a pair of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — an edge of the tree.

Next m lines contain queries. Each query is specified as a pair of integers ti, vi (1 ≤ ti ≤ 2, 1 ≤ vi ≤ n). If ti = 1, then as a reply to the query we need to paint a blue node vi in red. If ti = 2, then we should reply to the query by printing the shortest distance from some red node to node vi.

It is guaranteed that the given graph is a tree and that all queries are correct.

Output

For each second type query print the reply in a single line.

Examples

Input

5 4
1 2
2 3
2 4
4 5
2 1
2 5
1 2
2 5


Output

0
3
2
import java.io.*;
import java.util.*;
public class CentroidDecomposition 
{
	static ArrayList<Integer>[] g;
public static void main(String[] args) throws IOException {
	input.init(System.in);
	PrintWriter out = new PrintWriter(System.out);
	int n = input.nextInt(), m = input.nextInt();
	ArrayList<Integer>[] g = new ArrayList[n];
	for(int i = 0; i<n; i++) g[i] = new ArrayList<Integer>();
	for(int i = 0; i<n-1; i++)
	{
		int a = input.nextInt()-1, b = input.nextInt()-1;
		g[a].add(b);
		g[b].add(a);
	}
	LCA lca = new LCA(g);
	lca.binaryLift();
	CD cd = new CD(g);
	int[] res = new int[n];
	Arrays.fill(res, (int)1e9);
	int at = 0;
	while(at != -1)
	{
		res[at] = Math.min(res[at], lca.dist(at, 0));
		at = cd.cps[at];
	}
	for(int i = 0; i<m; i++)
	{
		int type = input.nextInt(), v = input.nextInt()-1;
		if(type == 1)
		{
			at = v;
			while(at != -1)
			{
				res[at] = Math.min(res[at], lca.dist(at, v));
				at = cd.cps[at];
			}
		}
		else
		{
			int min = (int)1e9;
			at = v;
			while(at != -1)
			{
				min = Math.min(res[at]+lca.dist(at, v), min);
				at = cd.cps[at];
			}
			out.println(min);
		}
	}
	out.close();
}
/*
 * LCA with O(n*log(n)) precomputation and O(log(n)) queries.
 */
static class LCA
{
	int[] depths, ps;
	int[][] bl;
	int n;
	ArrayList<Integer>[] g;
	LCA(ArrayList<Integer>[] g)
	{
		this.g = g;
		n = g.length;
		tree();
	}
	void tree()
	{
		ps = new int[n];
		depths = new int[n];
		boolean[] vis = new boolean[n];
		vis[0] = true;
		ps[0] = -1;
		Queue<Integer> q = new LinkedList<Integer>();
		q.add(0);
		ArrayList<Integer>[] tree = new ArrayList[n];
		for(int i = 0; i<n; i++) tree[i] = new ArrayList<Integer>();
		while(!q.isEmpty())
		{
			int at = q.poll();
			for(int e : g[at])
			{
				if(vis[e]) continue;
				tree[at].add(e);
				vis[e] = true;
				q.add(e);
				ps[e] = at;
				depths[e] = 1 + depths[at];
			}
		}
		g = tree;
	}
	int lca(int a, int b)
	{
		if(depths[a] < depths[b])
		{
			int temp = a; a = b; b = temp;
		}
		int log = 0;
		for(log = 1; (1<<log) <= depths[a]; log++);
		log--;
		for(int i = log; i >= 0; i--)
			if(depths[a] - (1<<i) >= depths[b])
				a = bl[i][a];
		if(a == b) return a;
		for(int i = log; i>=0; i--)
			if(bl[i][a] != -1 && bl[i][a] != bl[i][b])
			{
				a = bl[i][a];
				b = bl[i][b];
			}
		return ps[a];
	}
	/*
	 * Returns the distance between two nodes in the tree
	 */
	int dist(int a, int b)
	{
		int lca = lca(a, b);
		return depths[a] + depths[b] - 2 * depths[lca];
	}
	/*
	 * Returns the ancestor of at that is distance p away.
	 */
	int getParent(int at, int p)
	{
		if(p == 0) return at;
		int log = Integer.numberOfTrailingZeros(Integer.highestOneBit(p));
		return getParent(bl[log][at], p - (1<<log));
	}
	void binaryLift()
	{
		bl = new int[Integer.numberOfTrailingZeros(Integer.highestOneBit(n)) + 1][n];
		for(int i = 0; i<n; i++) bl[0][i] = ps[i];
		for(int i = 1; i < bl.length; i++)
		{
			Arrays.fill(bl[i], -1);
			for(int j = 0; j<n; j++)
				if(bl[i-1][j] >= 0)
					bl[i][j] = bl[i-1][bl[i-1][j]];
		}
	}
}
/*
 * Centroid Decomposition - O(n*log(n))
 * centroidDecomp is a tree with the centroid of g as the root.
 * The children of a node x are the centroids of the graph when x is removed.
 * The height of this tree is at most log(n).
 * cps is the array of parents in this tree.
 */
static class CD
{
	int n, root;
	ArrayList<Integer>[] g, centroidDecomp;
	boolean[] gone;
	int[] ps, st, cps;
	public CD(ArrayList<Integer>[] gg)
	{
		g = gg;
		n = g.length;
		cps = new int[n];
		Arrays.fill(cps, -1);
		ps = new int[n];
		st = new int[n];
		gone = new boolean[n];
		centroidDecomp = new ArrayList[n];
		for(int i = 0; i<n; i++) centroidDecomp[i] = new ArrayList<Integer>();
		root = findCentroid(0);
	}
	int findCentroid(int root)
	{
		ps[root] = -1;
		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
		q.add(root);
		ArrayList<Integer> order = new ArrayList<Integer>();
		while(!q.isEmpty())
		{
			int at = q.poll();
			order.add(at);
			for(int e : g[at])
			{
				if(gone[e] || e == ps[at]) continue;
				ps[e] = at;
				q.add(e);
			}
		}
		for(int ii = order.size()-1; ii>=0; ii--)
		{
			int i = order.get(ii);
			st[i] = 1;
			for(int e : g[i])
			{
				if(gone[e] || e == ps[i]) continue;
				st[i] += st[e];
			}
		}
		int size = order.size(), c = -1;
		for(int i : order)
		{
			boolean good = true;
			for(int e : g[i]) good &= gone[e] || e == ps[i] || st[e] <= size/2;
			if(good && size - st[i] <= size/2)
			{
				c = i;
				break;
			}
		}
		gone[c] = true;
		for(int e : g[c])
		{
			if(gone[e]) continue;
			int nc = findCentroid(e);
			centroidDecomp[c].add(nc);
			cps[nc] = c;
		}
		return c;
	}
}
public static class input {
	static BufferedReader reader;
	static StringTokenizer tokenizer;

	static void init(InputStream input) {
		reader = new BufferedReader(new InputStreamReader(input));
		tokenizer = new StringTokenizer("");
	}

	static String next() throws IOException {
		while (!tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(reader.readLine());
		return tokenizer.nextToken();
	}

	static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
}
}

