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 N = 1e5 + 5;
int timer, tmin[N], tmout[N], sz[N], par[N][25], n, m, u, v, t, L, fix[N], p[N],
    best[N], k, h[N];
vector<int> V[N], C[N];
void dfs(int u) {
  timer++;
  tmin[u] = timer;
  best[u] = 2 * N;
  for (int j = 1; j <= L; j++) {
    par[u][j] = par[par[u][j - 1]][j - 1];
  }
  for (int i = 0; i < V[u].size(); i++) {
    if (V[u][i] == par[u][0]) continue;
    par[V[u][i]][0] = u;
    dfs(V[u][i]);
    sz[u] += sz[V[u][i]];
  }
  tmout[u] = timer;
  sz[u]++;
}
void addEdge(int u, int v) {
  C[u].push_back(v);
  V[v].push_back(u);
}
int find_centroid(int u, int p, int Sz) {
  for (int i = 0; i < V[u].size(); i++) {
    if (V[u][i] != p && !fix[V[u][i]] && sz[V[u][i]] > Sz / 2)
      return find_centroid(V[u][i], u, Sz);
  }
  return u;
}
void find_size(int u, int p) {
  sz[u] = 0;
  for (int i = 0; i < V[u].size(); i++) {
    if (fix[V[u][i]] || V[u][i] == p) continue;
    find_size(V[u][i], u);
    sz[u] += sz[V[u][i]];
  }
  sz[u]++;
}
void new_tree(int u, int P) {
  find_size(u, 0);
  int c = find_centroid(u, u, sz[u]);
  p[c] = P;
  h[c] = h[P] + 1;
  fix[c] = 1;
  for (int i = 0; i < V[c].size(); i++) {
    if (!fix[V[c][i]]) {
      new_tree(V[c][i], c);
    }
  }
}
bool check(int u, int v) {
  if (tmin[u] <= tmin[v] && tmout[u] >= tmout[v]) return 1;
  return 0;
}
int up(int u, int v) {
  if (check(u, v)) return 0;
  int D = 0, U = u;
  for (int i = L; i >= 0; i--) {
    if (par[u][i] && !check(par[u][i], v)) u = par[u][i], D += 1 << i;
  }
  D++;
  return D;
}
int find_dist(int u, int v) { return up(u, v) + up(v, u); }
void update(int u) {
  int U = u;
  while (u) {
    best[u] = min(best[u], find_dist(U, u));
    u = p[u];
  }
}
int getans(int u) {
  int pas = 2 * N, U = u;
  while (u) {
    pas = min(pas, find_dist(U, u) + best[u]);
    u = p[u];
  }
  return pas;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  L = log2(n) + 1;
  for (k = 2; k <= n; k++) {
    cin >> u >> v;
    V[u].push_back(v);
    V[v].push_back(u);
  }
  dfs(1);
  new_tree(1, 0);
  update(1);
  while (m--) {
    cin >> t >> v;
    if (t == 1) {
      update(v);
    } else
      cout << getans(v) << " ";
  }
}
