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 INF = int(1e9);
vector<set<int> > gr;
vector<int> para, ht;
int maxad;
int l;
int timw, timi[200005], timo[200005];
int up[200005][21];
void lcaini(int n) {
  gr = vector<set<int> >(n + 1);
  para = vector<int>(n + 1);
  ht = vector<int>(n + 1);
  timw = 0;
  l = 20;
}
int dfsr(int u, int par, int dep) {
  timi[u] = timw++;
  para[u] = par;
  ht[u] = dep;
  int ko = dep + 1;
  up[u][0] = par;
  for (int i = 1; i <= l; i++) {
    up[u][i] = up[up[u][i - 1]][i - 1];
  }
  maxad = max(maxad, dep);
  for (auto x : gr[u]) {
    if (x == par) continue;
    dfsr(x, u, ko);
  }
  timo[u] = timw++;
  return 0;
}
bool is_ancestor(int u, int v) {
  return timi[u] <= timi[v] && timo[u] >= timo[v];
}
int lca(int a, int b) {
  if (ht[a] > ht[b]) swap(a, b);
  int d = ht[b] - ht[a];
  for (int i = 0; i < l; i++)
    if (d & (1 << i)) b = up[b][i];
  if (a == b) return a;
  for (int i = l - 1; i >= 0; i--)
    if (up[a][i] != up[b][i]) a = up[a][i], b = up[b][i];
  return up[a][0];
}
int lcdist(int u, int v) { return ht[u] + ht[v] - 2 * ht[lca(u, v)]; }
int nn;
int cpar[200005], sub[200005];
void cdfs1(int u, int p) {
  sub[u] = 1;
  nn++;
  for (auto it : gr[u]) {
    if (it != p) {
      cdfs1(it, u);
      sub[u] += sub[it];
    }
  }
}
int cdfs2(int u, int p) {
  for (auto it : gr[u])
    if (it != p && sub[it] > nn / 2) return cdfs2(it, u);
  return u;
}
void decompose(int root, int p) {
  nn = 0;
  cdfs1(root, root);
  int centroid = cdfs2(root, root);
  if (p == -1) p = centroid;
  cpar[centroid] = p;
  for (auto it : gr[centroid]) {
    gr[it].erase(centroid);
    decompose(it, centroid);
  }
  gr[centroid].clear();
}
int ans[200005];
void update(int u) {
  int x = u;
  ans[x] = 0;
  while (x != cpar[x]) {
    x = cpar[x];
    ans[x] = min(ans[x], lcdist(x, u));
  }
}
void query(int u) {
  int ansa = ans[u];
  int x = u;
  while (x != cpar[x]) {
    x = cpar[x];
    ansa = min(ansa, ans[x] + lcdist(x, u));
  }
  cout << ansa << "\n";
}
int main() {
  int n, m;
  cin >> n >> m;
  lcaini(n + 1);
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    gr[x].insert(y);
    gr[y].insert(x);
  }
  dfsr(1, 1, 0);
  decompose(1, -1);
  for (int i = 0; i <= n; i++) ans[i] = INF;
  update(1);
  while (m--) {
    int x, y;
    cin >> x >> y;
    switch (x) {
      case 1:
        update(y);
        break;
      case 2:
        query(y);
        break;
    }
  }
}
