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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Queue;
import java.util.LinkedList;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author beginner1010
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        final int SQRT = 316;
        final int LOG = 17;
        int[] distance;
        ArrayList<Integer>[] adj;
        int[][] parent;
        int[] depth;

        void bfs(ArrayList<Integer> sources) {
            Queue<Integer> Q = new LinkedList<>();
            for (int source : sources) {
                distance[source] = 0;
                Q.add(source);
            }
            while (!Q.isEmpty()) {
                int cur = Q.poll();
                for (int neighbor : adj[cur]) {
                    if (distance[neighbor] > distance[cur] + 1) {
                        distance[neighbor] = distance[cur] + 1;
                        Q.add(neighbor);
                    }
                }
            }
            sources.clear();
        }

        void dfs(int node, int father, int d) {
            parent[0][node] = father;
            depth[node] = d;
            for (int child : adj[node]) {
                if (child == father)
                    continue;
                dfs(child, node, d + 1);
            }
        }

        int lca(int a, int b) {
            if (depth[a] < depth[b]) {
                return lca(b, a);
            }
            for (int j = LOG - 1; j >= 0; j--) {
                if (depth[a] - (1 << j) >= depth[b]) {
                    a = parent[j][a];
                }
            }
            if (a == b)
                return a;

            for (int j = LOG - 1; j >= 0; j--) {
                if (parent[j][a] != parent[j][b]) {
                    a = parent[j][a];
                    b = parent[j][b];
                }
            }
            a = parent[0][a];
            b = parent[0][b];
            assert (a == b);
            return a;
        }

        int minDist(int a, int b) {
            return depth[a] + depth[b] - 2 * depth[lca(a, b)];
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            adj = new ArrayList[n];
            for (int i = 0; i < n; i++) {
                adj[i] = new ArrayList<>();
            }

            for (int i = 0; i < n - 1; i++) {
                int x = in.nextInt() - 1;
                int y = in.nextInt() - 1;
                adj[x].add(y);
                adj[y].add(x);
            }

            parent = new int[LOG][n];
            depth = new int[n];
            dfs(0, 0, 0);
            for (int j = 1; j < LOG; j++) {
                for (int i = 0; i < n; i++) {
                    parent[j][i] = parent[j - 1][parent[j - 1][i]];
                }
            }

            ArrayList<Integer> sources = new ArrayList<>();
            sources.add(0);
            distance = new int[n];
            Arrays.fill(distance, n);
            bfs(sources);

            for (int i = 0; i < m; i++) {
                int type = in.nextInt();
                int vertex = in.nextInt() - 1;
                if (type == 1) {
                    sources.add(vertex);
                    if (sources.size() == SQRT)
                        bfs(sources);
                } else {
                    assert (type == 2);
                    int ans = distance[vertex];
                    for (int source : sources) {
                        ans = Math.min(ans, minDist(vertex, source));
                    }
                    out.println(ans);
                }
            }
        }

    }

    static class InputReader {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputStream stream;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isWhitespace(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isWhitespace(c));
            return res * sgn;
        }

    }
}

