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.stream.Stream;
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 int[] depth;
        LCASchieberVishkin lcaSchieberVishkin;

        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int Q = in.nextInt();
            List<Integer>[] tree = CollectionUtils.generateListArray(n);
            for (int i = 0; i < n - 1; i++) {
                int u = in.nextInt() - 1;
                int v = in.nextInt() - 1;
                tree[u].add(v);
                tree[v].add(u);
            }
            depth = depthOfTree(tree, 0);
            CentroidDecomposition centroidDecomposition = new CentroidDecomposition(tree, n);
            lcaSchieberVishkin = new LCASchieberVishkin(tree, 0);
            int[] best = depth.clone();
            for (int q = 0; q < Q; q++) {
                char type = in.nextCharacter();
                int v = in.nextInt() - 1;
                int ans = Integer.MAX_VALUE;
                for (int u = v; u >= 0; u = centroidDecomposition.centroidDecompositionParent[u]) {
                    if (type == '1') {
                        best[u] = Math.min(best[u], distance(u, v));
                    } else {
                        ans = Math.min(ans, best[u] + distance(u, v));
                    }
                }
                if (type == '2') {
                    out.println(ans);
                }
            }
        }

        public int distance(int a, int b) {
            int lca = lcaSchieberVishkin.LowestCommonAncestor(a, b);
            return depth[a] + depth[b] - 2 * depth[lca];
        }

        public static int[] depthOfTree(List<Integer>[] tree, int root) {
            int n = tree.length;
            int[] depth = new int[n];
            int[] parents = new int[n];
            ArrayUtils.fill(parents, -1);
            int[] Q = new int[n];
            Q[0] = root;
            for (int p = 0, r = 1; p < r; p++) {
                int cur = Q[p];
                for (Integer next : tree[cur]) {
                    if (parents[cur] != next) {
                        Q[r++] = next;
                        depth[next] = depth[cur] + 1;
                        parents[next] = cur;
                    }
                }
            }
            return depth;
        }

        public 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 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 CollectionUtils {
        public static List[] generateListArray(int size) {
            return Stream.generate(ArrayList::new).limit(size).toArray(List[]::new);
        }

    }

    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 char nextCharacter() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char) c;
        }

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

        }

    }

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

    }

    static class LCASchieberVishkin {
        public int[] parent;
        public int[] preOrder;
        public int[] I;
        public int[] head;
        public int[] A;
        public int time;

        public LCASchieberVishkin(List<Integer>[] tree, int root) {
            int n = tree.length;
            preOrder = new int[n];
            I = new int[n];
            head = new int[n];
            A = new int[n];
            parent = new int[n];

            dfs1(tree, root, -1);
            dfs2(tree, root, -1, 0);
        }

        public void dfs1(List<Integer>[] tree, int u, int p) {
            parent[u] = p;
            I[u] = preOrder[u] = time++;
            for (int v : tree[u]) {
                if (v == p) continue;
                dfs1(tree, v, u);
                if (Integer.lowestOneBit(I[v]) > Integer.lowestOneBit(I[u])) {
                    I[u] = I[v];
                }
            }
            head[I[u]] = u;
        }

        public void dfs2(List<Integer>[] tree, int u, int p, int up) {
            A[u] = up | Integer.lowestOneBit(I[u]);
            for (int v : tree[u]) {
                if (v == p) continue;
                dfs2(tree, v, u, A[u]);
            }
        }

        public int enterIntoStrip(int x, int hz) {
            if (Integer.lowestOneBit(I[x]) == hz)
                return x;
            int hw = Integer.highestOneBit(A[x] & (hz - 1));
            return parent[head[I[x] & (~hw + 1) | hw]];
        }

        public int LowestCommonAncestor(int x, int y) {
            int hb = I[x] == I[y] ? Integer.lowestOneBit(I[x]) : Integer.highestOneBit(I[x] ^ I[y]);
            int hz = Integer.lowestOneBit(A[x] & A[y] & (~hb + 1));
            int ex = enterIntoStrip(x, hz);
            int ey = enterIntoStrip(y, hz);
            return preOrder[ex] < preOrder[ey] ? ex : ey;
        }

    }
}