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;
set<int> adj[100010];
int level[100010];
int parent[100010];
int dp[100010][30];
void dfs(int node, int dad, int deep) {
  level[node] = deep;
  parent[node] = dad;
  for (auto it = adj[node].begin(); it != adj[node].end(); it++) {
    if (*it != dad) dfs(*it, node, deep + 1);
  }
}
void preprocess(void) {
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < 30; j++) {
      dp[i][j] = -1;
    }
  }
  for (int i = 1; i <= N; i++) {
    dp[i][0] = parent[i];
  }
  for (int j = 1; (1 << j) <= N; j++) {
    for (int i = 1; i <= N; i++) {
      if (dp[i][j - 1] != -1) {
        dp[i][j] = dp[dp[i][j - 1]][j - 1];
      }
    }
  }
}
int lca(int p, int q) {
  if (level[p] < level[q]) swap(p, q);
  int foo;
  for (foo = 1; (1 << foo) <= level[p]; foo++)
    ;
  foo--;
  for (int i = foo; i >= 0; i--) {
    if ((level[p] - (1 << i)) >= level[q]) p = dp[p][i];
  }
  if (p == q) return p;
  for (int i = foo; i >= 0; i--) {
    if (dp[p][i] != dp[q][i] and dp[p][i] != -1) {
      p = dp[p][i];
      q = dp[q][i];
    }
  }
  return parent[p];
}
int dist(int a, int b) { return level[a] + level[b] - 2 * level[lca(a, b)]; }
int par[100010], subtree[100010];
int ans[100010];
int treesize;
void Cdfs1(int node, int p) {
  treesize++;
  subtree[node] = 1;
  for (auto it = adj[node].begin(); it != adj[node].end(); it++) {
    if (*it != p) {
      Cdfs1(*it, node);
      subtree[node] += subtree[*it];
    }
  }
}
int Cdfs2(int node, int p) {
  for (auto it = adj[node].begin(); it != adj[node].end(); it++) {
    if (*it != p and subtree[*it] > treesize / 2) return Cdfs2(*it, node);
  }
  return node;
}
void CentroidDecompose(int root, int p) {
  treesize = 0;
  Cdfs1(root, root);
  int centroid = Cdfs2(root, root);
  if (p == -1) p = centroid;
  par[centroid] = p;
  for (auto it = adj[centroid].begin(); it != adj[centroid].end(); it++) {
    adj[*it].erase(centroid);
    CentroidDecompose(*it, centroid);
  }
  adj[centroid].clear();
}
void update(int u) {
  int x = u;
  while (1) {
    ans[u] = min(ans[u], dist(u, x));
    if (u == par[u]) break;
    u = par[u];
  }
}
int query(int u) {
  int ret = 1000000007;
  int x = u;
  while (1) {
    ret = min(ret, ans[u] + dist(u, x));
    if (u == par[u]) break;
    u = par[u];
  }
  return ret;
}
int main() {
  int i, j, k;
  scanf("%d", &N);
  scanf("%d", &Q);
  for (i = 0; i < N - 1; i++) {
    int u, v;
    scanf("%d", &u);
    scanf("%d", &v);
    adj[u].insert(v);
    adj[v].insert(u);
  }
  dfs(1, 0, 0);
  preprocess();
  CentroidDecompose(1, -1);
  for (i = 1; i < 100010; i++) ans[i] = 1000000007;
  update(1);
  while (Q--) {
    int type, v;
    scanf("%d", &type);
    scanf("%d", &v);
    if (type == 1)
      update(v);
    else {
      int retans = query(v);
      printf("%d\n", retans);
    }
  }
  return 0;
}
