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 = 1e5 + 10;
int n, m;
std::vector<int> adj[N];
int ban[N];
int numChild[N];
int lim;
int papa[N];
void minimize(int &a, int b) { a = min(a, b); }
void dfs_numchild(int u, int dady) {
  numChild[u] = 1;
  for (int v : adj[u]) {
    if (v == dady || ban[v]) continue;
    dfs_numchild(v, u);
    numChild[u] += numChild[v];
  }
}
int getCentroid(int u, int dady) {
  for (int v : adj[u]) {
    if (v == dady || ban[v]) continue;
    if (numChild[v] > lim) return getCentroid(v, u);
  }
  return u;
}
void centree(int u, int dady) {
  dfs_numchild(u, u);
  lim = numChild[u] / 2;
  int x = getCentroid(u, u);
  ban[x] = 1;
  papa[x] = dady;
  for (int v : adj[x]) {
    if (ban[v]) continue;
    centree(v, x);
  }
}
int best[N];
int timer;
int euler[N], last[N];
int dep[N];
int par[N][20];
void genlca(int u, int dady) {
  dep[u] = dep[dady] + 1;
  par[u][0] = dady;
  euler[u] = ++timer;
  for (int v : adj[u]) {
    if (v == dady) continue;
    genlca(v, u);
  }
  last[u] = timer;
}
int anc(int u, int v) { return euler[u] <= euler[v] && last[v] <= last[u]; }
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  if (anc(v, u)) return v;
  for (int bit = 19; bit >= 0; bit--)
    if (!anc(par[u][bit], v)) u = par[u][bit];
  return par[u][0];
}
int dist(int u, int v) {
  int o = lca(u, v);
  return dep[u] + dep[v] - 2 * dep[o];
}
void init() {
  centree(1, 0);
  genlca(1, 1);
  for (int bit = 1; bit < 20; bit++)
    for (int u = 1; u <= n; u++) par[u][bit] = par[par[u][bit - 1]][bit - 1];
  memset(best, 0x3f3f3f3f, sizeof best);
}
void update(int u) {
  int du = u;
  while (du != 0) {
    minimize(best[du], dist(u, du));
    du = papa[du];
  }
}
void ask(int u) {
  int res = 0x3f3f3f3f;
  int du = u;
  while (du != 0) {
    minimize(res, dist(u, du) + best[du]);
    du = papa[du];
  }
  cout << res << '\n';
}
int main() {
  if (fopen("main.in", "r"))
    assert(freopen("main.in", "r", stdin));
  else if (fopen("342E"
                 ".inp",
                 "r"))
    assert(
        freopen("342E"
                ".inp",
                "r", stdin)),
        assert(freopen("342E"
                       ".out",
                       "w", stdout));
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  init();
  update(1);
  while (m--) {
    int x, y;
    cin >> x >> y;
    if (x == 1) {
      update(y);
    } else {
      ask(y);
    }
  }
}
