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 num;
int sub[100050], level[100050], ans[100050];
set<int> nodes[100050];
int parent[100050], par[100050];
int lcap[100050][20];
int calcSize(int x, int p) {
  num++;
  sub[x] = 1;
  for (auto i : nodes[x]) {
    if (i != p) sub[x] += calcSize(i, x);
  }
  return sub[x];
}
int getCentroid(int x, int p) {
  for (auto i : nodes[x]) {
    if (sub[i] > num / 2 and i != p) {
      return getCentroid(i, x);
    }
  }
  return x;
}
void decompose(int x, int p) {
  num = 0;
  calcSize(x, p);
  int centroid = getCentroid(x, p);
  parent[centroid] = p;
  for (auto i : nodes[centroid]) {
    nodes[i].erase(centroid);
    decompose(i, centroid);
  }
}
void dfs(int x, int p, int depth) {
  par[x] = p;
  level[x] = depth;
  for (auto i : nodes[x]) {
    if (i != p) dfs(i, x, depth + 1);
  }
}
void lcaDp(int n, int root) {
  memset(lcap, -1, sizeof lcap);
  dfs(root, -1, 1);
  for (int i = 1; i <= n; i++) lcap[i][0] = par[i];
  for (int j = 1; 1 << j < n; j++)
    for (int i = 1; i <= n; i++)
      if (lcap[i][j - 1] != -1) lcap[i][j] = lcap[lcap[i][j - 1]][j - 1];
}
int getLCA(int a, int b) {
  if (level[b] > level[a]) {
    swap(b, a);
  }
  int x = log2(level[a]);
  for (int i = x; i >= 0; i--) {
    if (level[a] - (1 << i) >= level[b]) {
      a = lcap[a][i];
    }
  }
  if (a == b) return a;
  x = log2(level[a]);
  for (int i = x; i >= 0; i--) {
    if (lcap[a][i] > 0 && lcap[a][i] != lcap[b][i]) {
      a = lcap[a][i], b = lcap[b][i];
    }
  }
  return lcap[a][0];
}
int getDist(int a, int b) {
  return level[a] + level[b] - 2 * level[getLCA(a, b)];
}
int query(int u) {
  int res = 1e9;
  int x = u;
  while (u > 0) {
    res = min(res, ans[u] + getDist(x, u));
    u = parent[u];
  }
  return res;
}
void upd(int u) {
  int x = u;
  while (u > 0) {
    ans[u] = min(ans[u], getDist(x, u));
    u = parent[u];
  }
}
int main() {
  int n, a, b, m;
  cin >> n >> m;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    nodes[a].insert(b);
    nodes[b].insert(a);
  }
  for (int i = 1; i <= n; i++) {
    ans[i] = 1e9;
  }
  lcaDp(n, 1);
  decompose(1, -1);
  upd(1);
  while (m > 0) {
    cin >> a >> b;
    if (a == 1) {
      upd(b);
    } else {
      cout << query(b) << endl;
    }
    m--;
  }
}
