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 = 2e5 + 5;
const int maxe = 18;
int padre[maxn], ans[maxn];
int L[maxn], lca[maxn][maxe];
int sons[maxn];
int n, m, nn;
void dfs(int u, int p, const vector<set<int>> &ady) {
  for (auto v : ady[u]) {
    if (v != p) {
      L[v] = L[u] + 1;
      lca[v][0] = u;
      dfs(v, u, ady);
    }
  }
}
void precompute_lca(const vector<set<int>> &ady) {
  dfs(1, -1, ady);
  for (int j = 1; j < maxe; j++)
    for (int i = 1; i <= n; i++) lca[i][j] = lca[lca[i][j - 1]][j - 1];
}
int query_LCA(int a, int b) {
  if (L[a] > L[b]) swap(a, b);
  int dif = L[b] - L[a];
  for (int i = 0; i < maxe; i++)
    if (dif & (1 << i)) b = lca[b][i];
  if (a == b) return a;
  for (int i = maxe - 1; i >= 0; i--)
    if (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 L[a] + L[b] - 2 * L[query_LCA(a, b)]; }
int get_cent(int root, const vector<set<int>> &ady) {
  nn = 0;
  function<void(int, int)> get_sz = [&](int u, int p) {
    sons[u] = 1;
    nn++;
    for (auto v : ady[u]) {
      if (v != p) {
        get_sz(v, u);
        sons[u] += sons[v];
      }
    }
  };
  get_sz(root, -1);
  function<int(int, int)> gc = [&](int u, int p) {
    for (auto v : ady[u]) {
      if (v != p && sons[v] > nn / 2) return gc(v, u);
    }
    return u;
  };
  return gc(root, -1);
}
void precompute_centroid(int u, vector<set<int>> &ady) {
  int n = (int)ady.size();
  function<void(int, int)> dfs = [&](int u, int p) {
    int c = get_cent(u, ady);
    if (p == -1)
      padre[c] = c;
    else
      padre[c] = p;
    for (auto v : ady[c]) {
      ady[v].erase(c);
      dfs(v, c);
    }
    ady[c].clear();
  };
  dfs(u, -1);
}
void update(int u) {
  int x = u;
  while (1) {
    ans[x] = min(ans[x], dist(u, x));
    if (padre[x] == x) break;
    x = padre[x];
  }
}
int query(int u) {
  int x = u, r = 1 << 30;
  while (1) {
    r = min(r, ans[x] + dist(u, x));
    if (padre[x] == x) break;
    x = padre[x];
  }
  cout << endl;
  return r;
}
int main() {
  scanf("%d%d", &n, &m);
  fill(ans + 1, ans + n + 1, 1 << 30);
  vector<set<int>> ady(n + 1);
  int a, b;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    ady[a].insert(b);
    ady[b].insert(a);
  }
  precompute_lca(ady);
  precompute_centroid(1, ady);
  update(1);
  while (m--) {
    scanf("%d%d", &a, &b);
    if (a == 1)
      update(b);
    else
      printf("%d\n", query(b));
  }
}
