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;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
const int INF = 0x3f3f3f3f, N = 1e5 + 5;
const ll LINF = 1e18 + 5;
int n, m, blo, d[N];
int id[N << 1], first[N], dep[N << 1], tot, dp[N << 1][25], dis[N];
bool col[N];
vector<int> G[N], red;
void dfs1(int u, int fa) {
  for (int v : G[u]) {
    if (v ^ fa) {
      d[v] = d[u] + 1;
      dis[v] = dis[u] + 1;
      dfs1(v, u);
    }
  }
}
void dfs(int u, int fa, int depth) {
  id[++tot] = u;
  first[u] = tot;
  dep[tot] = depth;
  for (int v : G[u]) {
    if (v == fa) continue;
    dfs(v, u, depth + 1);
    id[++tot] = u;
    dep[tot] = depth;
  }
}
inline int MIN(int x, int y) { return dep[x] < dep[y] ? x : y; }
void ST(int n) {
  for (int i = 1; i <= n; i++) dp[i][0] = i;
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      dp[i][j] = MIN(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
}
int RMQ(int l, int r) {
  int k = 0;
  while ((1 << (k + 1)) <= r - l + 1) k++;
  return MIN(dp[l][k], dp[r - (1 << k) + 1][k]);
}
int LCA(int x, int y) {
  x = first[x], y = first[y];
  if (x > y) swap(x, y);
  return id[RMQ(x, y)];
}
int disontree(int x, int y) { return dis[x] + dis[y] - 2 * dis[LCA(x, y)]; }
void update() {
  queue<pii> q;
  bitset<N> vis;
  vis.reset();
  for (int x : red) {
    q.push(make_pair(x, 0));
    vis[x] = 1;
    d[x] = 0;
  }
  red.clear();
  while ((int)q.size()) {
    int u = q.front().first, step = q.front().second;
    q.pop();
    for (int v : G[u]) {
      if (!vis[v]) {
        d[v] = min(d[v], step + 1);
        q.push(make_pair(v, step + 1));
        vis[v] = 1;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  blo = sqrt(m);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  col[1] = 1;
  dfs1(1, 0);
  dfs(1, 0, 1);
  ST(2 * n - 1);
  while (m--) {
    int op, x;
    cin >> op >> x;
    if (op == 1) {
      if (!col[x]) {
        red.push_back(x);
        col[x] = 1;
        if ((int)red.size() >= blo) update();
      }
    } else {
      int ans = d[x];
      for (int v : red) {
        int cur = disontree(x, v);
        if (cur < ans) ans = cur;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
