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 = 4e5 + 10;
const int MAXLOG = 20;
const int INF = 2e9;
int n, m, size, tot, dfn;
int red[N], dep[N], dist[N], lg[N], mn[N][MAXLOG], pos[N], fa[N];
vector<int> g[N];
template <typename T>
inline void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
inline void chkmin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= f;
}
inline void DFS(int u) {
  mn[++dfn][0] = u;
  pos[u] = dfn;
  for (auto v : g[u]) {
    if (v == fa[u]) continue;
    fa[v] = u;
    dep[v] = dep[u] + 1;
    dist[v] = dep[v];
    DFS(v);
    mn[++dfn][0] = u;
  }
}
inline int get(int x, int y) { return dep[x] < dep[y] ? x : y; }
inline void initST() {
  lg[0] = -1;
  for (int i = 1; i <= 2 * n; ++i) lg[i] = lg[i >> 1] + 1;
  for (int j = 1; j <= lg[n * 2 - 1]; ++j)
    for (int i = 1; i < 2 * n && i + (1 << j) - 1 < 2 * n; ++i)
      mn[i][j] = get(mn[i][j - 1], mn[i + (1 << (j - 1))][j - 1]);
  return;
}
inline void BFS() {
  queue<int> q;
  for (int i = 1; i <= tot; ++i) {
    q.push(red[i]);
    dist[red[i]] = 0;
  }
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (auto v : g[cur]) {
      if (dist[cur] + 1 < dist[v]) {
        dist[v] = dist[cur] + 1;
        q.push(v);
      }
    }
  }
  return;
}
inline int lca(int x, int y) {
  x = pos[x], y = pos[y];
  if (x > y) swap(x, y);
  int d = lg[y - x + 1];
  return get(mn[x][d], mn[y - (1 << d) + 1][d]);
}
inline int calc(int x, int y) { return dep[x] + dep[y] - 2 * dep[lca(x, y)]; }
int main() {
  read(n);
  read(m);
  size = sqrt(n);
  for (int i = 1; i < n; ++i) {
    int x, y;
    read(x);
    read(y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 1; i <= n; ++i) dist[i] = INF;
  dist[1] = 0;
  DFS(1);
  initST();
  while (m--) {
    int type, u;
    read(type);
    read(u);
    if (type == 1) {
      red[++tot] = u;
      if (tot == size) {
        BFS();
        tot = 0;
        continue;
      }
    } else {
      int ans = dist[u];
      for (int i = 1; i <= tot; ++i) chkmin(ans, calc(u, red[i]));
      printf("%d\n", ans);
    }
  }
  return 0;
}
