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 MAX = 1e5 + 10;
const int LOG = 18;
int n, m, par[MAX][LOG], h[MAX];
vector<int> graph[MAX];
int par_tree[MAX], mini[MAX];
void lca_dfs(int node, int p) {
  if (p + 1) h[node] = h[p] + 1;
  par[node][0] = p;
  for (int k = 1; k < LOG; k++)
    if (par[node][k - 1] + 1) par[node][k] = par[par[node][k - 1]][k - 1];
  for (auto& target : (graph[node])) {
    if (target != p) lca_dfs(target, node);
  }
}
int get_lca(int a, int b) {
  if (h[b] > h[a]) swap(a, b);
  for (int k = LOG - 1; k >= 0; k--) {
    if (par[a][k] + 1 && h[par[a][k]] >= h[b]) a = par[a][k];
  }
  if (a == b) return a;
  for (int k = LOG - 1; k >= 0; k--)
    if (par[a][k] != par[b][k]) {
      a = par[a][k];
      b = par[b][k];
    }
  return par[a][0];
}
int dist(int a, int b) { return h[a] + h[b] - 2 * h[get_lca(a, b)]; }
int processed[MAX], sizes[MAX];
int get_sizes(int node, int p) {
  sizes[node] = 1;
  for (auto& target : (graph[node])) {
    if (!processed[target] && target != p)
      sizes[node] += get_sizes(target, node);
  }
  return sizes[node];
}
int cent, cent_cost;
void select_cent(int node, int p, int current) {
  int node_max = sizes[current] - sizes[node];
  for (auto& target : (graph[node])) {
    if (!processed[target] && target != p) {
      node_max = max(node_max, sizes[target]);
      select_cent(target, node, current);
    }
  }
  if (node_max < cent_cost) {
    cent = node;
    cent_cost = node_max;
  }
}
int process(int current) {
  get_sizes(current, -1);
  if (sizes[current] <= 1) return current;
  cent = current;
  cent_cost = ((int)1e9 + 10);
  select_cent(current, -1, current);
  int centroid = cent;
  processed[centroid] = 1;
  for (auto& target : (graph[centroid])) {
    if (!processed[target]) {
      int next_cent = process(target);
      par_tree[next_cent] = centroid;
    }
  }
  return centroid;
}
void update(int node) {
  int cur = node;
  while (cur > 0) {
    mini[cur] = min(mini[cur], dist(cur, node));
    cur = par_tree[cur];
  }
}
int query(int node) {
  int cur = node, ans = ((int)1e9 + 10);
  while (cur > 0) {
    ans = min(ans, mini[cur] + dist(node, cur));
    cur = par_tree[cur];
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  for (int(i) = (0); (i) < (MAX); (i)++) mini[i] = ((int)1e9 + 10);
  memset(par, -1, sizeof(par));
  cin >> n >> m;
  int a, b;
  for (int(i) = (0); (i) < (n - 1); (i)++) {
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  lca_dfs(1, -1);
  int root = process(1);
  par_tree[root] = -1;
  int type, node;
  update(1);
  for (int(k) = (0); (k) < (m); (k)++) {
    cin >> type >> node;
    if (type == 1) {
      update(node);
    } else {
      cout << (query(node)) << "\n";
      ;
    }
  }
}
