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;
struct CD {
  vector<int> par, lvl;
  vector<int> stsz;
  vector<vector<int> > dist;
  vector<bool> iscd;
  vector<vector<int> > g;
  CD(int n)
      : par(n),
        lvl(n),
        g(n, vector<int>()),
        stsz(n),
        iscd(n, false),
        dist(n, vector<int>(17)) {}
  void add_edge(int u, int v) {
    g[u].push_back(v);
    g[v].push_back(u);
  }
  void decompose() { centroid(0, -1); }
  void centroid(int nd, int pc) {
    dfs(nd, -1, 1, pc == -1 ? -1 : lvl[pc]);
    int u = find_cd(nd, stsz[nd]);
    iscd[u] = true;
    par[u] = pc;
    if (pc == -1)
      lvl[u] = 0;
    else
      lvl[u] = lvl[pc] + 1;
    for (auto &nxt : (g[u])) {
      if (!iscd[nxt]) centroid(nxt, u);
    }
  }
  void dfs(int nd, int p, int dis, int plvl) {
    if (plvl != -1) dist[nd][plvl] = dis;
    stsz[nd] = 1;
    for (auto &nxt : (g[nd])) {
      if (iscd[nxt] || nxt == p) continue;
      dfs(nxt, nd, dis + 1, plvl);
      stsz[nd] += stsz[nxt];
    }
  }
  int find_cd(int nd, int sz) {
    for (auto &nxt : (g[nd]))
      if (!iscd[nxt] && stsz[nxt] < stsz[nd] && stsz[nxt] > sz / 2)
        return find_cd(nxt, sz);
    return nd;
  }
  int lca(int u, int v) {
    if (lvl[u] < lvl[v]) swap(u, v);
    while (lvl[u] > lvl[v]) u = par[u];
    if (u == v) return u;
    while (par[u] != par[v]) u = par[u], v = par[v];
    return par[u];
  }
  int nth_par(int u, int n) {
    assert(lvl[u] >= n);
    while (n--) u = par[u];
    return u;
  }
};
void redify(int nd, CD &cd, vector<int> &mn) {
  int tmp = nd;
  while (tmp != -1) {
    mn[tmp] = min(mn[tmp], cd.dist[nd][cd.lvl[tmp]]);
    tmp = cd.par[tmp];
  }
}
int query(int nd, CD &cd, vector<int> &mn) {
  int tmp = cd.par[nd], ret = mn[nd];
  while (tmp != -1) {
    ret = min(ret, mn[tmp] + cd.dist[nd][cd.lvl[tmp]]);
    tmp = cd.par[tmp];
  }
  return ret;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n, m, u, v;
  cin >> n >> m;
  CD cd(n);
  for (int i = 1; i < (n); ++i) {
    cin >> u >> v;
    u--;
    v--;
    cd.add_edge(u, v);
  }
  cd.decompose();
  vector<int> mn(n, 1e7);
  redify(0, cd, mn);
  for (int i = 0; i < (m); ++i) {
    cin >> u >> v;
    v--;
    if (u == 1)
      redify(v, cd, mn);
    else
      cout << (query(v, cd, mn)) << endl;
  }
  return 0;
}
