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 maxn = 1e5 + 5;
int sub_tree[maxn], n, T[maxn], P[maxn][22], L[maxn], par[maxn], ans[maxn], nn;
set<int> adj[maxn];
void lca_dfs(int u, int p) {
  T[u] = p;
  L[u] = (p > -1) ? L[p] + 1 : 0;
  for (int s : adj[u]) {
    if (s == p) continue;
    lca_dfs(s, u);
  }
}
void sub_dfs(int u, int p) {
  nn++;
  sub_tree[u] = 1;
  for (int nd : adj[u]) {
    if (nd == p) continue;
    sub_dfs(nd, u);
    sub_tree[u] += sub_tree[nd];
  }
}
int getCentroid(int u, int p) {
  for (int nd : adj[u]) {
    if (nd == p) continue;
    if (sub_tree[nd] > nn / 2) return getCentroid(nd, u);
  }
  return u;
}
void decompose(int u, int p) {
  nn = 0;
  sub_dfs(u, -1);
  int centroid = getCentroid(u, -1);
  par[centroid] = p;
  for (int nd : adj[centroid]) {
    adj[nd].erase(centroid);
    if (nd == p) continue;
    decompose(nd, centroid);
  }
  adj[centroid].clear();
}
void init_LCA(int n) {
  memset(P, -1, sizeof(P));
  L[1] = 0;
  lca_dfs(1, -1);
  for (int i = 1; i <= n; i++) {
    P[i][0] = T[i];
  }
  for (int j = 1; (1 << j) < n; j++) {
    for (int i = 1; i <= n; i++) {
      if (P[i][j - 1] != -1) P[i][j] = P[P[i][j - 1]][j - 1];
    }
  }
}
int lca_query(int p, int q) {
  int tmp, log, i;
  if (L[p] < L[q]) tmp = p, p = q, q = tmp;
  log = 1;
  while (1) {
    int next = log + 1;
    if ((1 << next) > L[p]) break;
    log++;
  }
  for (i = log; i >= 0; i--)
    if (L[p] - (1 << i) >= L[q]) p = P[p][i];
  if (p == q) return p;
  for (i = log; i >= 0; i--)
    if (P[p][i] != -1 && P[p][i] != P[q][i]) p = P[p][i], q = P[q][i];
  return T[p];
}
int getDist(int p, int q) {
  int lca = lca_query(p, q);
  return L[p] + L[q] - 2 * L[lca];
}
void update(int x) {
  int u = x;
  while (u != -1) {
    ans[u] = min(ans[u], getDist(u, x));
    u = par[u];
  }
}
void query(int x) {
  int mini = 1e8;
  int u = x;
  while (u != -1) {
    mini = min(mini, ans[u] + getDist(u, x));
    u = par[u];
  }
  printf("%d\n", mini);
}
int main() {
  int a, b, m;
  scanf("%d %d", &n, &m);
  ;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d %d", &a, &b);
    ;
    adj[a].insert(b);
    adj[b].insert(a);
  }
  init_LCA(n);
  decompose(1, -1);
  for (int i = 1; i <= n; i++) ans[i] = 1e8;
  update(1);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    ;
    if (a == 2)
      query(b);
    else
      update(b);
  }
}
