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 size[100000 + 5], c_par[100000 + 5], c_level[100000 + 5], level[100000 + 5];
set<int> g[100000 + 5];
int dp[100000 + 5][20], ans[100000 + 5], layer = 0;
bool vis[100000 + 5];
void dfs(int u, int p = 0, int l = 0) {
  dp[u][0] = p;
  level[u] = l;
  layer++;
  if (layer > 100001) exit(-2);
  for (int i = 1; i < 20; i++) {
    dp[u][i] = dp[dp[u][i - 1]][i - 1];
  }
  for (auto v : g[u]) {
    if (v == p) continue;
    dfs(v, u, l + 1);
  }
}
int lca(int u, int v) {
  if (level[u] < level[v]) swap(u, v);
  int d = level[u] - level[v];
  for (int i = 20 - 1; i >= 0; i--)
    if ((1 << i) & d) u = dp[u][i];
  if (u == v) return u;
  for (int i = 20 - 1; i >= 0; i--) {
    if (dp[u][i] == dp[v][i]) continue;
    u = dp[u][i], v = dp[v][i];
  }
  return dp[u][0];
}
int dist(int u, int v) { return level[u] + level[v] - 2 * level[lca(u, v)]; }
int calc_size(int u, int p) {
  size[u] = 0;
  for (auto v : g[u]) {
    if (v == p) continue;
    size[u] += calc_size(v, u);
  }
  return size[u] += 1;
}
int find_centroid(int u, int t_size, int p) {
  layer++;
  if (layer > 100001) exit(-1);
  for (auto v : g[u])
    if (v != p && 2 * size[v] > t_size) return find_centroid(v, t_size, u);
  return u;
}
void decompose(int u, int l, int parent) {
  layer = 0;
  int n_nodes = calc_size(u, -1);
  int centroid = find_centroid(u, n_nodes, parent);
  if (parent == -1) parent = centroid;
  c_par[centroid] = parent;
  c_level[centroid] = l;
  for (auto v : g[centroid]) {
    g[v].erase(centroid);
    decompose(v, l + 1, centroid);
  }
  g[u].clear();
  return;
}
void update(int u) {
  ans[u] = 0;
  int v = u;
  while (v) {
    ans[v] = min(ans[v], dist(u, v));
    v = c_par[v];
  }
}
int query(int u) {
  int v = u, t_ans = ans[u];
  while (v) {
    t_ans = min(t_ans, ans[v] + dist(u, v));
    v = c_par[v];
  }
  return t_ans;
}
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].insert(b);
    g[b].insert(a);
  }
  dfs(1);
  decompose(1, 0, 0);
  for (int i = 0; i <= n; i++) ans[i] = INT_MAX / 10;
  update(1);
  for (int i = 0; i < q; i++) {
    int t, x;
    scanf("%d%d", &t, &x);
    if (t == 1)
      update(x);
    else
      printf("%d\n", query(x));
  }
  return 0;
}
