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 = (int)2e5 + 5;
vector<int> adj[N], ctree[N];
int level[N], subsize[N], cpar[N];
bool iscentroid[N];
void dfs_on_ctree(int u, int pre) {
  cpar[u] = pre;
  for (int i = 0; i < ctree[u].size(); i++) {
    int v = ctree[u][i];
    if (v == pre) continue;
    dfs_on_ctree(v, u);
  }
}
void dfs(int u, int pre) {
  subsize[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == pre || iscentroid[v]) continue;
    dfs(v, u);
    subsize[u] += subsize[v];
  }
}
int findCentroid(int u, int pre, int total) {
  bool flag = 1;
  int heaviest = 0;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == pre || iscentroid[v]) continue;
    if (subsize[v] > total / 2) flag = 0;
    if (subsize[v] > subsize[heaviest]) heaviest = v;
  }
  if (flag) return u;
  return findCentroid(heaviest, u, total);
}
int getCentroid(int u) {
  dfs(u, -1);
  return findCentroid(u, -1, subsize[u]);
}
int decompose(int u, int lvl) {
  int centroid = getCentroid(u);
  iscentroid[centroid] = 1;
  level[centroid] = lvl;
  for (int i = 0; i < adj[centroid].size(); i++) {
    int v = adj[centroid][i];
    if (!iscentroid[v]) {
      int nextcentroid = decompose(v, lvl + 1);
      ctree[centroid].push_back(nextcentroid);
      ctree[nextcentroid].push_back(centroid);
    }
  }
  return centroid;
}
const int H = 18;
int parent[H][N], depth[N];
void dfs_lca(int u, int pre, int dep) {
  parent[0][u] = pre;
  depth[u] = dep;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == pre) continue;
    dfs_lca(v, u, dep + 1);
  }
}
void precompute_lca() {
  for (int i = 1; i <= H; i++)
    for (int j = 1; j <= N; j++)
      if (parent[i - 1][j] != -1)
        parent[i][j] = parent[i - 1][parent[i - 1][j]];
}
int lca(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  int dif = depth[u] - depth[v];
  for (int i = 0; i < H; i++)
    if ((dif >> i) & 1) u = parent[i][u];
  if (u == v) return u;
  for (int i = H - 1; i >= 0; i--) {
    if (parent[i][u] != parent[i][v]) {
      u = parent[i][u];
      v = parent[i][v];
    }
  }
  return parent[0][u];
}
const int INF = (int)1e9 + 5;
int n, m, ans[N];
int dist(int u, int v) {
  int LCA = lca(u, v);
  return depth[u] - depth[LCA] + depth[v] - depth[LCA];
}
void update(int u) {
  int x = u;
  while (x != -1) {
    ans[x] = min(ans[x], dist(x, u));
    x = cpar[x];
  }
}
int query(int u) {
  int ret = INF;
  int x = u;
  while (x != -1) {
    ret = min(ret, dist(x, u) + ans[x]);
    x = cpar[x];
  }
  return ret;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  memset(parent, -1, sizeof parent);
  dfs_lca(1, -1, 0);
  precompute_lca();
  int root = decompose(1, 0);
  memset(cpar, -1, sizeof cpar);
  dfs_on_ctree(root, -1);
  for (int i = 1; i <= n; i++) ans[i] = INF;
  update(1);
  for (int i = 0; i < m; i++) {
    int op, u;
    scanf("%d %d", &op, &u);
    if (op == 1)
      update(u);
    else if (op == 2)
      printf("%d\n", query(u));
  }
  return 0;
}
