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;
vector<int> ADJ[1000000];
vector<int> adj[1000000];
int VIS[1000000];
int lvl[1000000];
int VISS[1000000];
int dis[100000];
bool DEL[1000000];
int P[1000000];
int dp[1000000][20];
int cur[1000000];
int n, m;
int tim = 1;
int sz[1000000];
int cnt = 0;
void DFFS(int v) {
  VISS[v] = tim;
  cnt++;
  sz[v] = 1;
  if (tim == 1) cur[dis[v]] = v;
  for (int i = 0; i < ADJ[v].size(); i++) {
    int u = ADJ[v][i];
    if (VISS[u] == tim || DEL[u]) continue;
    if (tim == 1) dis[u] = dis[v] + 1;
    DFFS(u);
    sz[v] += sz[u];
  }
  if (tim == 1) {
    for (int i = 0; i < 20; i++) {
      if (dis[v] - (1 << i) >= 0) dp[v][i] = cur[dis[v] - (1 << i)];
    }
  }
}
int id;
void DFS(int v) {
  VIS[v] = tim;
  for (int i = 0; i < ADJ[v].size(); i++) {
    int u = ADJ[v][i];
    if (VIS[u] == tim || DEL[u]) continue;
    if (sz[u] * 2 > cnt) DFS(u);
  }
  if (id == -1) id = v;
}
void decompose(int v, int pa) {
  id = -1;
  cnt = 0;
  DFFS(v);
  DFS(v);
  int x = id;
  if (pa != -1) adj[pa].push_back(x), adj[x].push_back(pa);
  tim++;
  P[x] = pa;
  DEL[x] = 1;
  int k = ADJ[x].size();
  for (int i = 0; i < ADJ[x].size(); i++) {
    int u = ADJ[x][i];
    if (DEL[u]) continue;
    decompose(u, x);
  }
}
int LCA(int u, int v) {
  if (dis[u] > dis[v]) swap(u, v);
  int x = dis[v] - dis[u];
  for (int i = 0; i < 20; i++)
    if (x & (1 << i)) v = dp[v][i];
  if (u == v) return v;
  for (int i = 19; i >= 0; i--)
    if (dp[v][i] != dp[u][i]) v = dp[v][i], u = dp[u][i];
  return dp[v][0];
}
int dist(int v, int u) { return dis[v] + dis[u] - 2 * dis[LCA(u, v)]; }
int ans[1000000];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) ans[i] = 100000000;
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    ADJ[x].push_back(y);
    ADJ[y].push_back(x);
  }
  decompose(1, -1);
  int pp = 0;
  for (int i = -1; i < m; i++) {
    int t, v;
    if (i >= 0)
      scanf("%d%d", &t, &v);
    else
      t = 1, v = 1;
    if (t == 1) {
      int u = v;
      pp = 0;
      while (v != -1) {
        ans[v] = min(ans[v], dist(u, v));
        v = P[v];
      }
    } else {
      int ret = 100000000;
      int u = v;
      pp = 0;
      while (v != -1) {
        ret = min(ret, ans[v] + dist(v, u));
        v = P[v];
      }
      printf("%d\n", ret);
    }
  }
}
