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 = 1 << 19, LOG = 20, infty = 1e9;
int n, m;
vector<int> adj[N];
int sz[N], par[N][LOG], pre[N], post[N], czas, deg[N];
void predfs(int v) {
  sz[v] = 1;
  pre[v] = ++czas;
  for (auto u : adj[v])
    if (par[u][0] == 0) {
      deg[u] = deg[v] + 1;
      par[u][0] = v;
      sz[v] += sz[u];
      predfs(u);
    }
  post[v] = ++czas;
}
bool jestprzodkiem(int a, int b) {
  return pre[a] <= pre[b] && post[b] <= post[a];
}
int lca(int a, int b) {
  if (jestprzodkiem(a, b)) return a;
  for (int i = LOG - 1; i >= 0; --i)
    if (!jestprzodkiem(par[a][i], b)) a = par[a][i];
  return par[a][0];
}
int dist(int a, int b) { return deg[a] + deg[b] - 2 * deg[lca(a, b)]; }
int block[N], cent_par[N], visited[N];
int find_centroid(int v, int all) {
  for (auto u : adj[v]) {
    if (sz[u] < sz[v] && sz[u] * 2 > all) return find_centroid(u, all);
    if (sz[u] > sz[v] && (all - sz[v]) * 2 > all) return find_centroid(u, all);
  }
  return v;
}
int calc_size(int v, int lvl) {
  sz[v] = 1;
  visited[v] = lvl;
  for (auto u : adj[v])
    if (!block[u] && visited[u] < lvl) sz[v] += calc_size(u, lvl);
  return sz[v];
}
void cent_dec(int v, int lvl, int elo = 0) {
  v = find_centroid(v, calc_size(v, lvl));
  cent_par[v] = elo;
  block[v] = 1;
  for (auto u : adj[v])
    if (!block[u]) cent_dec(u, lvl + 1, v);
}
int D[N];
void mark(int v) {
  int u = v;
  while (u != 0) {
    D[u] = min(D[u], dist(u, v));
    u = cent_par[u];
  }
}
int query(int v) {
  int u = v, res = infty;
  while (u != 0) {
    res = min(res, dist(u, v) + D[u]);
    u = cent_par[u];
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  par[1][0] = 1;
  predfs(1);
  for (int i = 1; i < LOG; ++i)
    for (int v = 1; v <= n; ++v) par[v][i] = par[par[v][i - 1]][i - 1];
  cent_dec(1, 1);
  for (int i = 1; i <= n; ++i) D[i] = infty;
  mark(1);
  for (int i = 1; i <= m; ++i) {
    int t, v;
    scanf("%d%d", &t, &v);
    if (t == 1)
      mark(v);
    else
      printf("%d\n", query(v));
  }
  return 0;
}
