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;
int N, M;
vector<int> S, P, D;
vector<int> ChainLength, ChainOffset, Chains;
int HLD;
vector<vector<int>> E, Q;
vector<pair<int, int>> C;
vector<int> V;
struct SegTree {
  SegTree(int size) {
    of = V.size();
    S = 1;
    while (S < size) S *= 2;
    V.resize(of + 2 * S);
    fill(V.begin() + of, V.end(), int(1e8));
  }
  void set(int i, int v) {
    V[of + (i += S)] = v;
    while (i > 1) {
      V[of + i / 2] = min(V[of + i], V[of + i ^ 1]);
      i /= 2;
    }
  }
  int get(int l, int r) { return get(1, 0, S, l, r); }
  int get(int i, int L, int R, int l, int r) {
    if (l <= L && r >= R) return V[of + i];
    int M = (L + R) / 2;
    if (r <= M) return get(2 * i, L, M, l, r);
    if (l >= M) return get(2 * i + 1, M, R, l, r);
    return min(get(2 * i, L, M, l, r), get(2 * i + 1, M, R, l, r));
  }
  int of, S;
};
vector<SegTree> LO, HI;
int dfs(int u, int p) {
  P[u] = p;
  S[u] = 1;
  for (int v : E[u]) {
    if (v != p) S[u] += dfs(v, u);
  }
  return S[u];
}
void dfs2(int u, int ch) {
  if (ch == ChainLength.size()) {
    ChainLength.push_back(0);
    ChainOffset.push_back(HLD);
  }
  C[u] = {ch, ChainLength[ch]++};
  Chains[HLD++] = u;
  for (int v : E[u])
    if (P[u] != v && 2 * S[v] >= S[u]) dfs2(v, ch);
  for (int v : E[u])
    if (P[u] != v && 2 * S[v] < S[u]) dfs2(v, ChainLength.size());
}
int main() {
  cin >> N >> M;
  HLD = 0;
  V.reserve(4 * N);
  S.resize(N);
  E.resize(N);
  C.resize(N);
  P.resize(N);
  D.resize(N);
  Chains.resize(N);
  fill(D.begin(), D.end(), int(1e8));
  for (int i = 0; i < N - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  dfs(0, -1);
  dfs2(0, 0);
  for (int i = 0; i < ChainLength.size(); ++i) {
    LO.emplace_back(ChainLength[i]);
    HI.emplace_back(ChainLength[i]);
  }
  LO[0].set(0, 0);
  HI[0].set(0, 0);
  D[0] = 0;
  for (int i = 0; i < M; ++i) {
    int t, v;
    cin >> t >> v;
    --v;
    if (t == 1) {
      int l = 0;
      while (v != -1) {
        int ch = C[v].first, d = C[v].second;
        if (D[v] <= l) break;
        D[v] = l;
        LO[ch].set(d, l - d);
        HI[ch].set(d, l + d);
        l += d + 1;
        v = P[Chains[ChainOffset[ch] + 0]];
      }
    } else {
      int ans = int(1e8);
      int l = 0;
      while (v != -1) {
        int ch = C[v].first, d = C[v].second;
        ans = min(ans, l + LO[ch].get(0, d + 1) + d);
        ans = min(ans, l + HI[ch].get(d, ChainLength[ch]) - d);
        l += d + 1;
        v = P[Chains[ChainOffset[ch] + 0]];
      }
      cout << ans << '\n';
    }
  }
}
