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;
vector<int> tree[100005];
bitset<100005> mark;
int size[100005];
int PC[100005];
int P[100005][20];
int L[100005];
void DFS(int u, int p) {
  size[u] = 1;
  for (int v : tree[u]) {
    if (v == p || mark[v]) continue;
    DFS(v, u);
    size[u] += size[v];
  }
}
int TC(int u, int p, int sz) {
  bool flag = 1;
  int hch = -1;
  for (int v : tree[u]) {
    if (v == p || mark[v]) continue;
    if (size[v] > (sz / 2)) flag = 0;
    if (hch == -1 || size[v] > size[hch]) hch = v;
  }
  if (flag && (sz - size[u]) <= (sz >> 1)) return u;
  return TC(hch, u, sz);
}
int CD(int u) {
  DFS(u, -1);
  int x = TC(u, -1, size[u]);
  mark[x] = 1;
  for (int v : tree[x]) {
    if (mark[v]) continue;
    int y = CD(v);
    PC[y] = x;
  }
  return x;
}
void DFS_LCA(int u, int p, int l) {
  P[u][0] = p;
  L[u] = l;
  for (int i = 1; (1 << i) <= l; i++) {
    P[u][i] = P[P[u][i - 1]][i - 1];
  }
  for (int v : tree[u]) {
    if (v == p) continue;
    DFS_LCA(v, u, l + 1);
  }
}
int lcaQuery(int u, int v) {
  if (L[u] < L[v]) swap(u, v);
  int i, j, lg = log2(L[u]);
  for (i = lg; i >= 0; i--) {
    j = P[u][i];
    if (j != -1 && L[j] >= L[v]) {
      u = j;
    }
  }
  if (u == v) return u;
  for (i = lg; i >= 0; i--) {
    j = P[u][i];
    if (j != -1 && j != P[v][i]) {
      u = j;
      v = P[v][i];
    }
  }
  return P[u][0];
}
multiset<pair<int, int> > path[100005];
void insert(int u) {
  int v = u;
  while (v != -1) {
    int lca = lcaQuery(u, v);
    int x = L[u] + L[v] - 2 * L[lca];
    path[v].insert({x, u});
    v = PC[v];
  }
}
int query(int u) {
  int v = u, q = INT_MAX;
  while (v != -1) {
    if (path[v].size() != 0) {
      int lca = lcaQuery(u, v);
      int x = (*path[v].begin()).first;
      int y = (L[u] + L[v] - 2 * L[lca]);
      x += y;
      if (q > x) q = x;
    }
    v = PC[v];
  }
  return q;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, i;
  cin >> n >> m;
  for (i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    tree[u].push_back(v);
    tree[v].push_back(u);
  }
  int x = CD(1);
  PC[x] = -1;
  memset(P, -1, sizeof P);
  DFS_LCA(1, -1, 1);
  insert(1);
  while (m--) {
    int op, u;
    cin >> op >> u;
    if (op == 1)
      insert(u);
    else
      cout << query(u) << "\n";
  }
  return 0;
}
