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.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.LinkedList;
import java.io.InputStream;

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

    static class TaskE {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int Q = in.nextInt();
            int[] from = new int[n - 1];
            int[] to = new int[n - 1];
            for (int i = 0; i < n - 1; i++) {
                from[i] = in.nextInt() - 1;
                to[i] = in.nextInt() - 1;
            }
            int[][] g = GraphUtils.packU(n, from, to);
            int[][] pars = GraphUtils.parents3(g, 0);
            int[] dep = pars[2];
            int[] spar = new int[n];
            ArrayUtils.fill(spar, -1);
            CentroidDecomposition centroidDecomposition = new CentroidDecomposition(g, spar);

            int[][] lpar = logstepParents(pars[0]);

            int[] d = Arrays.copyOf(dep, n);
            for (int q = 0; q < Q; q++) {
                int t = in.nextInt();
                int v = in.nextInt() - 1;
                if (t == 1) {
                    d[v] = 0;
                    for (int p = v; p != -1; p = spar[p]) {
                        int lca = lca2(p, v, lpar, dep);
                        d[p] = Math.min(d[p], dep[p] + dep[v] - 2 * dep[lca]);
                    }
                } else {
                    int ret = d[v];
                    for (int p = v; p != -1; p = spar[p]) {
                        int lca = lca2(p, v, lpar, dep);
                        ret = Math.min(ret, d[p] + dep[p] + dep[v] - 2 * dep[lca]);
                    }
                    out.println(ret);
                }
            }
        }

        public static int[][] logstepParents(int[] par) {
            int n = par.length;
            int m = Integer.numberOfTrailingZeros(Integer.highestOneBit(n - 1)) + 1;
            int[][] pars = new int[m][n];
            pars[0] = par;
            for (int j = 1; j < m; j++) {
                for (int i = 0; i < n; i++) {
                    pars[j][i] = pars[j - 1][i] == -1 ? -1 : pars[j - 1][pars[j - 1][i]];
                }
            }
            return pars;
        }

        public static int lca2(int a, int b, int[][] spar, int[] depth) {
            if (depth[a] < depth[b]) {
                b = ancestor(b, depth[b] - depth[a], spar);
            } else if (depth[a] > depth[b]) {
                a = ancestor(a, depth[a] - depth[b], spar);
            }

            if (a == b) return a;
            int sa = a, sb = b;
            for (int low = 0, high = depth[a], t = Integer.highestOneBit(high), k = Integer.numberOfTrailingZeros(t); t > 0; t >>>= 1, k--) {
                if ((low ^ high) >= t) {
                    if (spar[k][sa] != spar[k][sb]) {
                        low |= t;
                        sa = spar[k][sa];
                        sb = spar[k][sb];
                    } else {
                        high = low | t - 1;
                    }
                }
            }
            return spar[0][sa];
        }

        protected static int ancestor(int a, int m, int[][] spar) {
            for (int i = 0; m > 0 && a != -1; m >>>= 1, i++) {
                if ((m & 1) == 1) a = spar[i][a];
            }
            return a;
        }

    }

    static class ArrayUtils {
        public static void fill(int[] array, int value) {
            Arrays.fill(array, value);
        }

    }

    static class CentroidDecomposition {
        public List<Integer>[] tree;
        public boolean[] usedInDecomposition;
        public int[] subtreeSize;
        public int[] generation;
        public int lastGeneration;
        public int[] parent;
        public int[] centroidDecompositionParent;

        public CentroidDecomposition(List<Integer>[] tree, int n) {
            this.tree = tree;
            usedInDecomposition = new boolean[n];
            subtreeSize = new int[n];
            parent = new int[n];
            generation = new int[n];
            lastGeneration = 0;
            centroidDecompositionParent = new int[n];
            int root = decompose(0);
            centroidDecompositionParent[root] = -1;
        }

        public CentroidDecomposition(int[][] g, int[] spar) {
            int n = g.length;
            decompose(g, 0, new boolean[n], new int[n], new int[n], new int[n], spar);
        }

        public static int decompose(int[][] g, int root, boolean[] sed, int[] par, int[] ord, int[] des, int[] spar) {
            // parent and level - order
            ord[0] = root;
            par[root] = -1;
            int r = 1;
            for (int p = 0; p < r; p++) {
                int cur = ord[p];
                for (int next : g[cur]) {
                    if (par[cur] != next && !sed[next]) {
                        ord[r++] = next;
                        par[next] = cur;
                    }
                }
            }
            // DP and find a separator
            int sep = -1; // always exists
            outer:
            for (int i = r - 1; i >= 0; i--) {
                int cur = ord[i];
                des[cur] = 1;
                for (int e : g[cur]) {
                    if (par[cur] != e && !sed[e]) des[cur] += des[e];
                }
                if (r - des[cur] <= r / 2) {
                    for (int e : g[cur]) {
                        if (par[cur] != e && !sed[e] && des[e] >= r / 2 + 1) continue outer;
                    }
                    sep = cur;
                    break;
                }
            }
            sed[sep] = true;
            for (int e : g[sep]) {
                if (!sed[e]) spar[decompose(g, e, sed, par, ord, des, spar)] = sep;
            }
            return sep;
        }

        public int decompose(int s) {
            List<Integer> component = new ArrayList<>();
            parent[s] = -1;
            ++lastGeneration;
            generation[s] = lastGeneration;
            Queue<Integer> queue = new LinkedList<>();
            queue.offer(s);
            while (!queue.isEmpty()) {
                int cur = queue.poll();
                component.add(cur);
                subtreeSize[cur] = 1;
                for (Integer next : tree[cur]) {
                    if (usedInDecomposition[next])
                        continue;
                    if (parent[cur] == next)
                        continue;
                    if (generation[next] != lastGeneration) {
                        parent[next] = cur;
                        queue.offer(next);
                    }
                }
            }
            for (int i = component.size() - 1; i > 0; i--) {
                int node = component.get(i);
                subtreeSize[parent[node]] += subtreeSize[node];
            }
            int c = -1;
            for (Integer cur : component) {
                boolean good = true;
                for (Integer next : tree[cur]) {
                    if (parent[cur] == next)
                        continue;
                    if (usedInDecomposition[next])
                        continue;
                    if (2 * subtreeSize[next] > component.size()) {
                        good = false;
                    }
                }
                if (2 * (component.size() - subtreeSize[cur]) > component.size()) {
                    good = false;
                }
                if (good) {
                    c = cur;
                    break;
                }
            }
            if (c < 0)
                throw new AssertionError();
            usedInDecomposition[c] = true;
            // c is a centroid of the subtree containing vertex s
            for (Integer next : tree[c]) {
                if (usedInDecomposition[next])
                    continue;
                centroidDecompositionParent[decompose(next)] = c;
            }
            return c;
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;
        private FastReader.SpaceCharFilter filter;

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

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

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

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

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

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class GraphUtils {
        public static int[][] packU(int n, int[] from, int[] to) {
            int[][] g = new int[n][];
            int[] p = new int[n];
            for (int f : from)
                p[f]++;
            for (int t : to)
                p[t]++;
            for (int i = 0; i < n; i++) {
                g[i] = new int[p[i]];
            }
            for (int i = 0; i < from.length; i++) {
                g[from[i]][--p[from[i]]] = to[i];
                g[to[i]][--p[to[i]]] = from[i];
            }
            return g;
        }

        public static int[][] parents3(int[][] g, int root) {
            int n = g.length;
            int[] par = new int[n];
            ArrayUtils.fill(par, -1);

            int[] depth = new int[n];
            depth[0] = 0;

            int[] q = new int[n];
            q[0] = root;
            for (int p = 0, r = 1; p < r; p++) {
                int cur = q[p];
                for (int nex : g[cur]) {
                    if (par[cur] != nex) {
                        q[r++] = nex;
                        par[nex] = cur;
                        depth[nex] = depth[cur] + 1;
                    }
                }
            }
            return new int[][]{par, q, depth};
        }

    }
}