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;
set<int> tree[100002];
int anc[100002][20], subsz[100002], level[100002], ans[100002], parent[100002];
void dfs0(int x, int par = -1) {
  for (auto it = tree[x].begin(); it != tree[x].end(); it++) {
    if (*it == par) continue;
    anc[*it][0] = x;
    level[*it] += level[x] + 1;
    dfs0(*it, x);
  }
}
void init_LCA(int n) {
  dfs0(1);
  for (int i = 0; i <= n; i++) ans[i] = (int)1e9;
  int lgn = (int)(log(n) / log(2)) + 1;
  for (int j = 1; j <= lgn; j++) {
    for (int i = 1; i <= n; i++) {
      anc[i][j] = anc[anc[i][j - 1]][j - 1];
    }
  }
}
int LCA(int p, int q) {
  int tmp, log, i;
  if (level[p] < level[q]) swap(p, q);
  for (log = 1; (1 << log) <= level[p]; log++)
    ;
  log--;
  for (i = log; i >= 0; i--) {
    if (level[p] - (1 << i) >= level[q]) p = anc[p][i];
  }
  if (p == q) return p;
  for (i = log; i >= 0; i--) {
    if (anc[p][i] != 0 && anc[p][i] != anc[q][i]) {
      p = anc[p][i];
      q = anc[q][i];
    }
  }
  return anc[p][0];
}
int dist(int u, int v) { return level[u] + level[v] - 2 * level[LCA(u, v)]; }
int nn;
void dfs1(int u, int p) {
  subsz[u] = 1;
  nn++;
  for (auto it = tree[u].begin(); it != tree[u].end(); it++) {
    if (*it != p) {
      dfs1(*it, u);
      subsz[u] += subsz[*it];
    }
  }
}
int dfs2(int u, int p) {
  for (auto it = tree[u].begin(); it != tree[u].end(); it++) {
    if (*it != p && subsz[*it] > (nn / 2)) {
      return dfs2(*it, u);
    }
  }
  return u;
}
void decompose(int root, int p) {
  nn = 0;
  dfs1(root, root);
  int centroid = dfs2(root, root);
  if (p == -1) p = centroid;
  parent[centroid] = p;
  for (auto it = tree[centroid].begin(); it != tree[centroid].end(); it++) {
    tree[*it].erase(centroid);
    decompose(*it, centroid);
  }
}
void update(int u) {
  int x = u;
  while (1) {
    ans[x] = min(ans[x], dist(x, u));
    if (x == parent[x]) break;
    x = parent[x];
  }
}
int query(int u) {
  int x = u;
  int ret = (int)1e9;
  while (1) {
    ret = min(ret, dist(u, x) + ans[x]);
    if (x == parent[x]) break;
    x = parent[x];
  }
  return ret;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    tree[u].insert(v);
    tree[v].insert(u);
  }
  init_LCA(n);
  decompose(1, -1);
  update(1);
  while (m--) {
    int t, node;
    scanf("%d%d", &t, &node);
    if (t == 1) {
      update(node);
    } else
      printf("%d\n", query(node));
  }
  return 0;
}
