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 N = 1e5 + 3;
int n, q, LN, total = 0;
vector<int> adj[N];
int childsz[N], d[N], dad[N], ans[N], dd[N];
int b[N][19];
void dfs(int u, int p) {
  for (int v : adj[u])
    if (v != p) {
      b[v][0] = u;
      d[v] = d[u] + 1;
      dfs(v, u);
    }
}
int lca(int u, int v) {
  if (d[u] >= d[v]) {
    int t = d[u] - d[v];
    for (int i = LN; i >= 0; --i)
      if (((t >> i) & 1) == 1) u = b[u][i];
    if (u == v) return u;
    for (int i = LN; i >= 0; --i)
      if (b[u][i] != b[v][i]) {
        u = b[u][i];
        v = b[v][i];
      }
    return b[u][0];
  } else
    return lca(v, u);
}
void dfs_subtree(int u, int p) {
  childsz[u] = 1;
  total++;
  for (int v : adj[u])
    if (v != p && !dd[v]) {
      dfs_subtree(v, u);
      childsz[u] += childsz[v];
    }
}
int find_centrol(int u, int p) {
  for (int v : adj[u])
    if (v != p && !dd[v]) {
      if (childsz[v] > total / 2) return find_centrol(v, u);
    }
  return u;
}
void centrol_decomposition(int u, int p) {
  total = 0;
  dfs_subtree(u, 0);
  int centrol = find_centrol(u, 0);
  dd[centrol] = 1;
  dad[centrol] = p;
  for (int v : adj[centrol])
    if (!dd[v]) centrol_decomposition(v, centrol);
}
int dist(int u, int x) { return d[u] + d[x] - 2 * d[lca(u, x)]; }
void update(int u) {
  int x = u;
  while (x != 0) {
    ans[x] = min(ans[x], dist(x, u));
    x = dad[x];
  }
}
void query(int u) {
  int res = N;
  int x = u;
  while (x != 0) {
    res = min(res, dist(u, x) + ans[x]);
    x = dad[x];
  }
  printf("%d\n", res);
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i <= n; ++i) dd[i] = 0;
  LN = (int)log2(n) + 1;
  for (int i = 1, x, y; i <= n - 1; ++i) {
    scanf("%d%d", &x, &y);
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 0);
  for (int k = 1; k <= LN; ++k)
    for (int u = 1; u <= n; ++u) b[u][k] = b[b[u][k - 1]][k - 1];
  centrol_decomposition(1, 0);
  for (int i = 0; i <= n; ++i) ans[i] = N;
  update(1);
  for (int i = 1, t, v; i <= q; ++i) {
    scanf("%d%d", &t, &v);
    if (t == 1)
      update(v);
    else if (t == 2)
      query(v);
  }
}
