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 INF = 1e9;
int n, m, a, b, u, v;
set<int> adj[100001];
const int maxN = 20;
int LCA[100001][maxN], level[100001], parent[100001], subtree[100001],
    res[100001];
void dfs(int node, int lev, int par) {
  level[node] = lev;
  LCA[node][0] = par;
  for (auto child : adj[node]) {
    if (child != par) {
      dfs(child, lev + 1, node);
    }
  }
}
void init() {
  memset(LCA, -1, sizeof LCA);
  dfs(1, 0, -1);
  for (int j = 1; j < maxN; j++) {
    for (int i = 1; i <= n; i++) {
      int par = LCA[i][j - 1];
      if (par != -1) LCA[i][j] = LCA[par][j - 1];
    }
  }
}
int LowestCommonAncestor(int a, int b) {
  if (level[b] < level[a]) swap(a, b);
  int d = level[b] - level[a];
  while (d > 0) {
    int i = log2(d);
    b = LCA[b][i];
    d -= (1 << i);
  }
  if (a == b) return a;
  for (int i = maxN - 1; i >= 0; i--) {
    if (LCA[a][i] != -1 && (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 (level[a] + level[b] - 2 * level[LowestCommonAncestor(a, b)]);
}
int dfs1(int node, int par) {
  subtree[node] = 1;
  for (int child : adj[node]) {
    if (child != par) {
      subtree[node] += dfs1(child, node);
    }
  }
  return subtree[node];
}
int dfs2(int node, int par, int subtreesize) {
  for (int child : adj[node]) {
    if (child != par && subtree[child] > subtreesize / 2)
      return dfs2(child, node, subtreesize);
  }
  return node;
}
void decompose(int node, int p) {
  int subtreeSize = dfs1(node, p);
  int centroid = dfs2(node, p, subtreeSize);
  parent[centroid] = p;
  for (int child : adj[centroid]) {
    adj[child].erase(centroid);
    decompose(child, centroid);
  }
}
void update(int node) {
  int curr = node;
  while (curr != -1) {
    res[curr] = min(res[curr], dist(curr, node));
    curr = parent[curr];
  }
}
int query(int node) {
  int curr = node;
  int ans = INF;
  while (curr != -1) {
    ans = min(ans, res[curr] + dist(node, curr));
    curr = parent[curr];
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    adj[u].insert(v);
    adj[v].insert(u);
  }
  init();
  for (int i = 0; i <= n; i++) res[i] = INF;
  decompose(1, -1);
  update(1);
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    if (a == 1)
      update(b);
    else
      cout << query(b) << "\n";
  }
  return 0;
}
