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>
int n, m, p[100005], s[100005], l, t[200005], d[100005], rmq[20][200005];
bool r[100005], u[100005];
std::vector<int> e[100005];
std::vector<int> a;
void dfs(int u, int d) {
  s[u] = l;
  rmq[0][l++] = d;
  for (auto v : e[u]) {
    if (v != p[u]) {
      p[v] = u;
      dfs(v, d + 1);
      rmq[0][l++] = d;
    }
  }
}
int find_min(int l, int r) {
  if (l > r) {
    return find_min(r, l);
  }
  int i = t[r - l + 1];
  return std::min(rmq[i][l], rmq[i][r - (1 << i) + 1]);
}
int dist(int u, int v) {
  return rmq[0][s[u]] - find_min(s[u], s[v]) + rmq[0][s[v]] -
         find_min(s[u], s[v]);
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    e[a].push_back(b);
    e[b].push_back(a);
  }
  dfs(1, 0);
  for (int i = 1; (1 << i) <= l; i++) {
    for (int j = 0; j < l; j++) {
      if (j + (1 << (i - 1)) < l) {
        rmq[i][j] = std::min(rmq[i - 1][j], rmq[i - 1][j + (1 << (i - 1))]);
      } else {
        rmq[i][j] = rmq[i - 1][j];
      }
    }
  }
  t[0] = -1;
  for (int i = 1; i <= l; i++) {
    t[i] = t[i / 2] + 1;
  }
  r[1] = true;
  for (int i = 0; i < m; i++) {
    if (i % 320 == 0) {
      std::queue<std::pair<int, int>> q;
      for (int j = 1; j <= n; j++) {
        if (r[j]) {
          q.push({j, 0});
          u[j] = true;
        } else {
          u[j] = false;
        }
      }
      while (!q.empty()) {
        int a = q.front().first, s = q.front().second;
        d[a] = s;
        for (auto b : e[a]) {
          if (!u[b]) {
            u[b] = true;
            q.push({b, s + 1});
          }
        }
        q.pop();
      }
      a.clear();
    }
    int t, v;
    scanf("%d %d", &t, &v);
    if (t == 1) {
      a.push_back(v);
      r[v] = true;
    } else {
      int res = d[v];
      for (auto u : a) {
        res = std::min(res, dist(u, v));
      }
      printf("%d\n", res);
    }
  }
}
