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
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
struct CentroidDecomposition {
  vector<vector<int>> T;
  vector<int> sz, P, rank;
  vector<bool> block;
  vector<vector<int>> dist;
  vector<int> res;
  int root;
  CentroidDecomposition(int n)
      : T(n),
        sz(n),
        P(n, -1),
        block(n),
        rank(n),
        root(0),
        dist(18, vector<int>(n)),
        res(n, inf) {}
  void addEdge(int a, int b) {
    T[a].emplace_back(b);
    T[b].emplace_back(a);
  }
  bool valid(int x, int p) { return x != p and not block[x]; }
  int dfs(int x, int p = -1) {
    sz[x] = 1;
    for (int v : T[x])
      if (valid(v, p)) sz[x] += dfs(v, x);
    return sz[x];
  }
  int get_centroid(int x, int p, int n) {
    for (int v : T[x])
      if (valid(v, p) and sz[v] > n >> 1) return get_centroid(v, x, n);
    return x;
  }
  void calc_dist(int x, int r, int p = -1, int h = 0) {
    dist[r][x] = h;
    for (int v : T[x])
      if (valid(v, p)) calc_dist(v, r, x, h + 1);
  }
  void decompose(int x, int p = -1, int r = 0) {
    int n = dfs(x);
    int cen = get_centroid(x, -1, n);
    calc_dist(cen, r);
    P[cen] = p;
    block[cen] = 1;
    rank[cen] = r;
    for (auto v : T[cen]) {
      if (block[v]) continue;
      decompose(v, cen, r + 1);
    }
  }
  int query(int x) {
    int ans = inf, root = x;
    while (root != -1) {
      ans = min(ans, dist[rank[root]][x] + res[root]);
      root = P[root];
    }
    return ans;
  }
  void update(int x) {
    int root = x;
    while (root != -1) {
      res[root] = min(res[root], dist[rank[root]][x]);
      root = P[root];
    }
  }
};
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  CentroidDecomposition solver(n);
  for (int i = 1; i <= n - 1; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    solver.addEdge(a - 1, b - 1);
  }
  solver.decompose(0);
  solver.update(0);
  while (q--) {
    int type, x;
    scanf("%d %d", &type, &x);
    if (type == 1) solver.update(x - 1);
    if (type == 2) printf("%d\n", solver.query(x - 1));
  }
  return 0;
}
