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 long long inff = 0x3f3f3f3f3f3f3f3f;
int n, m, x, y, fa[200008][20], d[200008], ans, deep[200008];
vector<int> g[200008], sd;
void dfs(int u, int faa) {
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v != faa) deep[v] = deep[u] + 1, dfs(v, u), fa[v][0] = u;
  }
}
void bz() {
  for (int i(1); i <= (18); ++i)
    for (int j(1); j <= (n); ++j) fa[j][i] = fa[fa[j][i - 1]][i - 1];
}
int lca(int x, int y) {
  if (deep[x] < deep[y]) swap(x, y);
  int d = deep[x] - deep[y];
  for (int i(0); i <= (18); ++i)
    if (d & (1 << i)) x = fa[x][i];
  if (x == y) return x;
  for (int i(18); i >= (0); --i)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
void djk() {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      q;
  for (int i = 0; i < sd.size(); i++)
    d[sd[i]] = 0, q.push(pair<int, int>(0, sd[i]));
  while (q.size()) {
    pair<int, int> p = q.top();
    q.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    int ss = g[v].size();
    for (int i(0); i <= (ss - 1); ++i) {
      int e = g[v][i];
      if (d[e] > d[v] + 1) d[e] = d[v] + 1, q.push(pair<int, int>(d[e], e));
    }
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i(1); i <= (n - 1); ++i) {
    scanf("%d", &x), scanf("%d", &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  memset(d, int(0x3f3f3f3f), sizeof(d));
  dfs(1, 0), bz();
  sd.push_back(1);
  n = sqrt(m);
  while (m--) {
    scanf("%d", &x);
    if (x == 1) {
      scanf("%d", &y), sd.push_back(y);
      if (sd.size() == n) djk(), sd.clear();
    } else {
      scanf("%d", &y);
      ans = d[y];
      for (int i = 0; i < sd.size(); i++)
        ans = min(deep[y] + deep[sd[i]] - 2 * deep[lca(y, sd[i])], ans);
      printf("%d\n", ans);
    }
  }
  return 0;
}
