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;
vector<int> d, sz, ans;
vector<vector<int>> g, pa;
void dfs(int i) {
  d[i] = d[pa[i][1]] + 1;
  for (int j : g[i])
    if (j != pa[i][1]) pa[j][1] = i, dfs(j);
}
int lca(int i, int j) {
  if (d[i] < d[j]) swap(i, j);
  for (int k = 19; k; --k)
    if (d[pa[i][k]] >= d[j]) i = pa[i][k];
  for (int k = 19; k; --k)
    if (pa[i][k] != pa[j][k]) i = pa[i][k], j = pa[j][k];
  return i == j ? i : pa[i][1];
}
int dis(int i, int j) { return d[i] + d[j] - d[lca(i, j)] * 2; }
void dfs(int i, int p) {
  sz[i] = 1;
  for (int j : g[i])
    if (pa[j][0] == -1 && j != p) dfs(j, i), sz[i] += sz[j];
}
int cen(int i, int p, int n) {
  for (int j : g[i])
    if (j != p && pa[j][0] == -1 && sz[j] > n / 2) return cen(j, i, n);
  return i;
}
void cd(int i, int p) {
  dfs(i, -1);
  int n = sz[i];
  int c = cen(i, -1, n);
  pa[c][0] = ~p ? p : c;
  for (int j : g[c])
    if (pa[j][0] == -1) cd(j, c);
}
void update(int i) {
  ans[i] = 0;
  int j = pa[i][0];
  for (; j != pa[j][0]; j = pa[j][0]) ans[j] = min(ans[j], dis(i, j));
  ans[j] = min(ans[j], dis(i, j));
}
void query(int i) {
  int tmp = ans[i];
  int j = pa[i][0];
  for (; j != pa[j][0]; j = pa[j][0]) tmp = min(tmp, dis(i, j) + ans[j]);
  tmp = min(tmp, dis(i, j) + ans[j]);
  cout << tmp << '\n';
}
int main() {
  int n, m;
  cin >> n >> m;
  d.resize(n), sz.resize(n), ans.assign(n, n), g.resize(n),
      pa.assign(n, vector<int>(20, -1));
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].push_back(y), g[y].push_back(x);
  }
  pa[0][1] = 0, d[0] = 0;
  dfs(0);
  for (int i = 2; i < 20; ++i)
    for (int j = 0; j < n; ++j) pa[j][i] = pa[pa[j][i - 1]][i - 1];
  cd(0, -1);
  update(0);
  while (m--) {
    int ty, x;
    cin >> ty >> x;
    --x;
    if (ty == 1)
      update(x);
    else
      query(x);
  }
}
