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>
int N, M, t, v;
std::vector<std::set<int>> T;
std::vector<int> H;
std::vector<int> S;
std::vector<int> P;
std::vector<int> D;
std::vector<std::array<int, 20>> Anc;
void dfs(int u, int p, int h) {
  H[u] = h;
  Anc[u][0] = p;
  for (int v : T[u])
    if (v != p) dfs(v, u, h + 1);
}
void ancestors() {
  for (int h = 1; h < 20; h++)
    for (int u = 0; u < N; u++)
      Anc[u][h] = (Anc[u][h - 1] == -1) ? -1 : Anc[Anc[u][h - 1]][h - 1];
}
int lca(int u, int v) {
  if (u == v) return u;
  if (H[u] < H[v]) return lca(v, u);
  int k = 19;
  while (H[u] - H[v] > 0) {
    while (H[u] - H[v] < (1 << k)) k--;
    u = Anc[u][k];
  }
  k = 19;
  while (u != v) {
    while (k > 0 && Anc[u][k] == Anc[v][k]) k--;
    u = Anc[u][k];
    v = Anc[v][k];
  }
  return u;
}
int dist(int u, int v) { return H[u] + H[v] - 2 * H[lca(u, v)]; }
int centroid(int u, int p, int s) {
  for (int v : T[u])
    if (v != p && S[v] > s / 2) return centroid(v, u, s);
  return u;
}
int size(int u, int p) {
  S[u] = 1;
  for (int v : T[u])
    if (v != p) S[u] += size(v, u);
  return S[u];
}
void decomposition(int u, int p) {
  int c = centroid(u, -1, size(u, -1));
  P[c] = p;
  for (int v : T[c]) {
    T[v].erase(c);
    decomposition(v, c);
  }
  T[c].clear();
}
void update(int u) {
  int v = u;
  while (v != -1) {
    D[v] = std::min(D[v], dist(u, v));
    v = P[v];
  }
}
int query(int u) {
  int v = u;
  int sol = 1e6;
  while (v != -1) {
    sol = std::min(sol, D[v] + dist(u, v));
    v = P[v];
  }
  return sol;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin >> N >> M;
  T.resize(N);
  H.resize(N, 0);
  S.resize(N, 0);
  P.resize(N, 0);
  D.resize(N, 1e6);
  Anc.resize(N);
  for (int i = 0; i < N - 1; i++) {
    std::cin >> t >> v;
    t--;
    v--;
    T[t].insert(v);
    T[v].insert(t);
  }
  dfs(0, -1, 0);
  ancestors();
  decomposition(0, -1);
  update(0);
  for (int i = 0; i < M; i++) {
    std::cin >> t >> v;
    v--;
    if (t == 1)
      update(v);
    else
      std::cout << query(v) << std::endl;
  }
  return 0;
}
