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 + 5;
set<int> st[N];
long long int Child[N], Par[N], Res[N], Nod;
long long int tbl[N][21], Dep[N], n, m;
void dfs0(int u, int p) {
  for (auto v : st[u]) {
    if (v == p) continue;
    tbl[v][0] = u;
    Dep[v] = Dep[u] + 1;
    dfs0(v, u);
  }
}
void sparse() {
  dfs0(0, 0);
  tbl[0][0] = 0;
  for (int i = 1; i < 21; i++) {
    for (int j = 0; j < n; j++) {
      tbl[j][i] = tbl[tbl[j][i - 1]][i - 1];
    }
  }
}
int _lca(int u, int v) {
  if (Dep[u] > Dep[v]) swap(u, v);
  int d = Dep[v] - Dep[u];
  for (int i = 0; i < 21; i++) {
    if (d & (1 << i)) v = tbl[v][i];
  }
  if (u == v) return u;
  for (int i = 20; i >= 0; i--) {
    if (tbl[v][i] != tbl[u][i]) u = tbl[u][i], v = tbl[v][i];
  }
  return tbl[u][0];
}
void dfs1(int u, int p) {
  Child[u] = 1;
  ++Nod;
  for (auto v : st[u]) {
    if (v == p) continue;
    dfs1(v, u);
    Child[u] += Child[v];
  }
}
int dfs2(int u, int p) {
  for (auto v : st[u]) {
    if (v == p || Child[v] <= Nod / 2) continue;
    return dfs2(v, u);
  }
  return u;
}
void Decomposed(int root, int p) {
  Nod = 0;
  dfs1(root, root);
  int centroid = dfs2(root, root);
  if (p == -1) p = centroid;
  Par[centroid] = p;
  for (auto it = st[centroid].begin(); it != st[centroid].end(); ++it) {
    int v = *it;
    st[v].erase(centroid);
    Decomposed(v, centroid);
  }
  st[centroid].clear();
}
long long int dist(int u, int v) {
  return (Dep[u] + Dep[v] - 2 * Dep[_lca(u, v)]);
}
void updt(int u) {
  int x = u;
  while (true) {
    Res[x] = min(Res[x], dist(x, u));
    if (x == Par[x]) break;
    x = Par[x];
  }
}
long long int Qry(int u) {
  int x = u;
  long long int Ret = 1e9 + 7;
  while (true) {
    Ret = min(Ret, dist(u, x) + Res[x]);
    if (x == Par[x]) break;
    x = Par[x];
  }
  return Ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    st[u].insert(v);
    st[v].insert(u);
  }
  sparse();
  Decomposed(0, -1);
  for (int i = 0; i < n; i++) Res[i] = 1e9 + 7;
  updt(0);
  while (m--) {
    int t, v;
    cin >> t >> v;
    --v;
    if (t == 1)
      updt(v);
    else {
      int Ret = Qry(v);
      cout << Ret << "\n";
    }
  }
  return 0;
}
