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
//package practice.pset1;

import java.io.*;
import java.util.*;

public class R342E {

    static ArrayList<Integer>[] adj;
    static int[][] anc;
    static int[][] dist_anc;
    static int lvl[];
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int q = sc.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 a = sc.nextInt()-1;
            int b = sc.nextInt()-1;

            adj[a].add(b);
            adj[b].add(a);
        }

        int[] par = new int[n];
        int[] ord = new int[n];
        lvl = new int[n];
        par[0] = -1;
        ord[0] = 0;
        lvl[0] = 0;
        for (int qst = 0, qen = 1; qst < qen;) {
            int u = ord[qst++];
            for(int v: adj[u]){
                if(v != par[u])
                {
                    par[v] = u;
                    ord[qen++] = v;
                    lvl[v] = lvl[u]+1;
                }
            }
        }

        anc = new int[20][n];
        dist_anc = new int[20][n];

        for (int i = 0; i < anc.length; i++)
            Arrays.fill(anc[i], -1);
        for (int i = 0; i < n; i++) {
            anc[0][i] = par[i];
            dist_anc[0][i] = 1;
        }

        // anc[i][n] = anc[i-1][anc[i-1][n]]
        for (int i = 1; i < 20; i++) {
            for (int j = 0; j < n; j++)
                if(anc[i-1][j] != -1) {
                    anc[i][j] = anc[i - 1][anc[i - 1][j]];
                    dist_anc[i][j] = dist_anc[i-1][j] + dist_anc[i-1][anc[i-1][j]];
                }
        }

        int[] min = new int[n];
        Arrays.fill(min, 1000000000);
        int[] cent_par = buildCentroidTree(adj);

        int red = 0;
        int par_red = red;
        while(par_red != -1){
            min[par_red] = Math.min(min[par_red], getDistance(par_red, red));
            par_red = cent_par[par_red];
        }
        while(q-->0){
            int type = sc.nextInt();
            int u = sc.nextInt()-1;
            int p = u;
            if(type == 1){
                while(p != -1){
                    min[p] = Math.min(min[p], getDistance(u, p));
                    p = cent_par[p];
                }
            }else{
                int ans = Integer.MAX_VALUE;
                while(p != -1){
                    ans = Math.min(ans, getDistance(p, u) + min[p]);
                    p = cent_par[p];
                }

                pw.println(ans);
            }
        }


        pw.flush();
        pw.close();
    }

    // a
    //   b
    static int MAX = 19;
    static int lca(int a, int b){
        if(lvl[a] > lvl[b]){
            int tmp = a;
            a = b;
            b = tmp;
        }

        for (int i = MAX; i >= 0; i--) {
            if(anc[i][b] == -1 || lvl[anc[i][b]] < lvl[a])
                continue;
            b = anc[i][b];
        }

        if(a == b)
            return a;

        for (int i = MAX; i >= 0; i--) {
            if(anc[i][b] == -1 || anc[i][b] == anc[i][a])
                continue;
            b = anc[i][b];
            a = anc[i][a];
        }

        return anc[0][a];
    }

    static int getDistance(int a, int b){
        int lca = lca(a, b);
        return dist(a, lca) + dist(b, lca);
    }

    static int dist(int a, int p){
        if(a == p)
            return 0;
        int dist = 0;
        for (int i = MAX; i >= 0; i--) {
            if(anc[i][a] == -1 || lvl[anc[i][a]] < lvl[p])
                continue;
            dist += dist_anc[i][a];
            a = anc[i][a];
        }
        return dist;
    }

    public static int[] buildCentroidTree(ArrayList<Integer>[] g) {
        int n = g.length;
        int[] ctpar = new int[n];
        Arrays.fill(ctpar, -1);
        buildCentroidTree(g, 0, new boolean[n], new int[n], new int[n], new int[n], ctpar);

        return ctpar;
    }

    private static int buildCentroidTree(ArrayList<Integer>[] g, int root, boolean[] dead, int[] par, int[] ord, int[] sz, int[] ctpar)
    {
        ord[0] = root;
        par[root] = -1;
        int r = 1;
        for(int p = 0;p < r;p++) {
            int cur = ord[p];
            for(int nex : g[cur]){
                if(par[cur] != nex && !dead[nex]){
                    ord[r++] = nex;
                    par[nex] = cur;
                }
            }
        }

        // DP and find a separator
        int sep = -1; // always exists
        outer:
        for(int i = r-1;i >= 0;i--){
            int cur = ord[i];
            sz[cur] = 1;
            for(int e : g[cur]){
                if(par[cur] != e && !dead[e])sz[cur] += sz[e];
            }
            if(r-sz[cur] <= r/2){
                for(int e : g[cur]){
                    if(par[cur] != e && !dead[e] && sz[e] >= r/2+1)continue outer;
                }
                sep = cur;
                break;
            }
        }

        dead[sep] = true;
        for(int e : g[sep]){
            if(!dead[e])ctpar[buildCentroidTree(g, e, dead, par, ord, sz, ctpar)] = sep;
        }
        return sep;
    }


    static class Scanner
    {
        StringTokenizer st; BufferedReader br;
        public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
        public Scanner(String s) throws FileNotFoundException {	br = new BufferedReader(new FileReader(new File(s)));}
        public String next() throws IOException {while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());return st.nextToken();}
        public int nextInt() throws IOException {return Integer.parseInt(next());}
        public long nextLong() throws IOException {return Long.parseLong(next());}
        public String nextLine() throws IOException {return br.readLine();}
        public boolean ready() throws IOException {return br.ready();}
    }
}
