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 depth[200005] = {0};
int dp[200005][20];
int size[200005] = {0};
int centPar[200005] = {0};
bool cent[200005] = {false};
int mn[200005];
vector<int> adj[200005];
void dfs(int u, int pre) {
  depth[u] = depth[pre] + 1;
  size[u] = 1;
  dp[u][0] = pre;
  mn[u] = 50000009;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v != pre) {
      dfs(v, u);
      size[u] += size[v];
    }
  }
}
void dfs1(int u, int pre, int sz, int cp) {
  int mxchild = 0;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (!cent[v] && size[v] > size[mxchild]) mxchild = v;
  }
  if (size[mxchild] <= sz / 2) {
    cent[u] = true;
    centPar[u] = cp;
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i];
      if (!cent[v]) dfs1(v, u, size[v], u);
    }
  } else {
    size[u] = sz - size[mxchild];
    size[mxchild] = sz;
    dfs1(mxchild, u, sz, cp);
  }
}
void lcaPre() {
  for (int i = 0; i < 200005; i++) {
    for (int j = 1; j < 19; j++) {
      dp[i][j] = -1;
    }
  }
  for (int j = 1; j < 19; j++) {
    for (int i = 0; i < 200005; i++) {
      if (dp[i][j - 1] != -1) dp[i][j] = dp[dp[i][j - 1]][j - 1];
    }
  }
}
int lca(int p, int q) {
  if (depth[p] < depth[q]) return lca(q, p);
  int diff = depth[p] - depth[q];
  for (int i = 0; i <= 19; i++)
    if (diff & (1 << i)) p = dp[p][i];
  if (p == q) return p;
  for (int i = 19 - 1; i >= 0; i--) {
    if (dp[p][i] != -1 && dp[q][i] != -1 && dp[p][i] != dp[q][i]) {
      p = dp[p][i];
      q = dp[q][i];
    }
  }
  return dp[p][0];
}
int dist(int a, int b) { return (depth[a] + depth[b] - 2 * depth[lca(a, b)]); }
void update(int u) {
  int tmp = u;
  while (tmp) {
    mn[tmp] = min(mn[tmp], dist(tmp, u));
    tmp = centPar[tmp];
  }
}
int query(int u) {
  int ans = 50000009;
  int tmp = u;
  while (tmp) {
    ans = min(ans, mn[tmp] + dist(tmp, u));
    tmp = centPar[tmp];
  }
  return ans;
}
int main() {
  int n, m, a, b;
  cin >> n >> m;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1, 0);
  dfs1(1, 0, n, 0);
  lcaPre();
  update(1);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (a == 1) {
      update(b);
    } else {
      cout << query(b) << endl;
    }
  }
  return 0;
}
