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;
int n, q, lv[100010], lca[100010][20], pct[100010], subt[100010], mk[100010],
    dp[100010];
vector<int> g[100010], gct[100010];
void dfs_1(int u) {
  for (auto v : g[u])
    if (!lv[v]) {
      lv[v] = lv[u] + 1;
      lca[v][0] = u;
      dfs_1(v);
    }
}
void prec_lca() {
  for (int i = 1; i < 20; i++)
    for (int j = 1; j <= n; j++) lca[j][i] = lca[lca[j][i - 1]][i - 1];
}
int LCA(int a, int b) {
  if (lv[b] > lv[a]) swap(a, b);
  for (int i = 31 - __builtin_clz(lv[a]); i >= 0; i--)
    if (lv[a] - (1 << i) >= lv[b] && lca[a][i]) a = lca[a][i];
  if (a == b) return a;
  for (int i = 31 - __builtin_clz(lv[a]); i >= 0; i--)
    if (lca[a][i] != lca[b][i] && lca[a][i] && lca[b][i])
      a = lca[a][i], b = lca[b][i];
  return lca[a][0];
}
int dist(int a, int b) { return lv[a] + lv[b] - 2 * lv[LCA(a, b)]; }
void dfs_2(int u, int p) {
  subt[u] = 1;
  for (auto v : g[u]) {
    if (v == p || mk[v]) continue;
    dfs_2(v, u);
    subt[u] += subt[v];
  }
}
int dfs_3(int u, int p, int root) {
  int nxt = -1;
  for (auto v : g[u])
    if (!mk[v] && v != p && subt[v] > subt[root] / 2) nxt = v;
  if (nxt == -1) return u;
  return dfs_3(nxt, u, root);
}
void build_ct(int root, int p) {
  dfs_2(root, p);
  int centroid = dfs_3(root, p, root);
  gct[p].push_back(centroid);
  pct[centroid] = p;
  mk[centroid] = 1;
  for (auto v : g[centroid])
    if (v != p && !mk[v]) {
      build_ct(v, centroid);
    }
}
void update(int a, int b) {
  while (a != 0) {
    dp[a] = min(dp[a], dist(a, b));
    a = pct[a];
  }
}
int query(int a, int b) {
  int res = 1000000007;
  while (a != 0) {
    res = min(res, dist(a, b) + dp[a]);
    a = pct[a];
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(0);
  cin >> n >> q;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  lv[1] = 1;
  dfs_1(1);
  prec_lca();
  build_ct(1, 0);
  fill(dp, dp + n + 1, 1000000007);
  update(1, 1);
  for (int i = 1; i <= q; i++) {
    int u, v;
    cin >> u >> v;
    if (u == 1)
      update(v, v);
    else
      cout << query(v, v) << '\n';
  }
  return 0;
}
