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 = 2e5 + 10, LG = 21, oo = 1e9 + 10;
bool vis[N];
int sub[N], P[N], d[N], L[N][LG], in[N], out[N], best[N], n, q;
vector<int> edges[N];
int find_size(int x, int p) {
  if (vis[x]) return 0;
  sub[x] = 1;
  for (int to : edges[x]) {
    if (to != p) {
      sub[x] += find_size(to, x);
    }
  }
  return sub[x];
}
int find_centroid(int x, int p, int size) {
  for (int to : edges[x]) {
    if (to != p && !vis[to] && size / 2 < sub[to])
      return find_centroid(to, x, size);
  }
  return x;
}
void build(int x, int p) {
  int c = find_centroid(x, -1, find_size(x, -1));
  P[c] = p;
  vis[c] = 1;
  for (int to : edges[c]) {
    if (!vis[to]) build(to, c);
  }
}
bool isAnc(int potAnc, int potChild) {
  return !potAnc || in[potAnc] <= in[potChild] && out[potAnc] >= out[potChild];
}
int lca(int x, int y) {
  if (isAnc(x, y)) return x;
  if (isAnc(y, x)) return y;
  for (int i = LG - 1; ~i; --i) {
    if (!isAnc(L[x][i], y)) x = L[x][i];
  }
  return L[x][0];
}
int dist(int u, int v) { return d[u] + d[v] - d[lca(u, v)] * 2; }
void update(int x) {
  int y = x;
  while (x) {
    best[x] = min(best[x], dist(x, y));
    x = P[x];
  }
}
int query(int x) {
  int bst = oo, y = x;
  while (x) {
    bst = min(bst, best[x] + dist(x, y));
    x = P[x];
  }
  return bst;
}
void dfs(int x, int p) {
  static int timer = 0;
  d[x] = d[p] + 1;
  in[x] = ++timer;
  L[x][0] = p;
  for (int i = 1; i < LG; ++i) L[x][i] = L[L[x][i - 1]][i - 1];
  for (int to : edges[x]) {
    if (to != p) {
      dfs(to, x);
    }
  }
  out[x] = ++timer;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) best[i] = oo;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  dfs(1, 0);
  build(1, -1);
  update(1);
  while (q--) {
    int type, vertex;
    cin >> type >> vertex;
    if (type == 1) {
      update(vertex);
    } else {
      cout << query(vertex) << '\n';
    }
  }
}
