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 N, Q;
set<int> adj[100010];
int f[100010][18], depth[100010], n;
void dfs(int u) {
  for (int i = 1; i < 18; i++) f[u][i] = f[f[u][i - 1]][i - 1];
  for (auto it = adj[u].begin(); it != adj[u].end(); it++) {
    int v = *it;
    if (!depth[v]) {
      f[v][0] = u;
      depth[v] = depth[u] + 1;
      dfs(v);
    }
  }
}
int lca(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  for (int i = 18 - 1; i >= 0; i--)
    if (depth[f[u][i]] >= depth[v]) {
      u = f[u][i];
    }
  if (u == v) return u;
  for (int i = 18 - 1; i >= 0; i--)
    if (f[u][i] != f[v][i]) {
      u = f[u][i];
      v = f[v][i];
    }
  return f[u][0];
}
int dist(int u, int v) {
  int x = lca(u, v);
  int res = depth[u] + depth[v] - 2 * depth[x];
  return res;
}
int par[100010], subtree[100010];
int ans[100010];
int treesize;
void Cdfs1(int node, int p) {
  treesize++;
  subtree[node] = 1;
  for (auto it = adj[node].begin(); it != adj[node].end(); it++) {
    if (*it != p) {
      Cdfs1(*it, node);
      subtree[node] += subtree[*it];
    }
  }
}
int Cdfs2(int node, int p) {
  for (auto it = adj[node].begin(); it != adj[node].end(); it++) {
    if (*it != p and subtree[*it] > treesize / 2) return Cdfs2(*it, node);
  }
  return node;
}
void CentroidDecompose(int root, int p) {
  treesize = 0;
  Cdfs1(root, root);
  int centroid = Cdfs2(root, root);
  if (p == -1) p = centroid;
  par[centroid] = p;
  for (auto it = adj[centroid].begin(); it != adj[centroid].end(); it++) {
    adj[*it].erase(centroid);
    CentroidDecompose(*it, centroid);
  }
  adj[centroid].clear();
}
void update(int u) {
  int x = u;
  while (1) {
    ans[u] = min(ans[u], dist(u, x));
    if (u == par[u]) break;
    u = par[u];
  }
}
int query(int u) {
  int ret = 1000000007;
  int x = u;
  while (1) {
    ret = min(ret, ans[u] + dist(u, x));
    if (u == par[u]) break;
    u = par[u];
  }
  return ret;
}
int main() {
  int i, j, k;
  scanf("%d", &N);
  scanf("%d", &Q);
  for (i = 0; i < N - 1; i++) {
    int u, v;
    scanf("%d", &u);
    scanf("%d", &v);
    adj[u].insert(v);
    adj[v].insert(u);
  }
  depth[1] = 1;
  dfs(1);
  CentroidDecompose(1, -1);
  for (i = 1; i < 100010; i++) ans[i] = 1000000007;
  update(1);
  while (Q--) {
    int type, v;
    scanf("%d", &type);
    scanf("%d", &v);
    if (type == 1)
      update(v);
    else {
      int retans = query(v);
      printf("%d\n", retans);
    }
  }
  return 0;
}
