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;
inline void I(long long &a) { cin >> a; }
const long long N = 1e5 + 10;
const long long LN = 17;
vector<long long> g[N];
vector<long long> t[N];
long long n;
long long val;
long long q;
long long sz[N];
long long used[N];
vector<long long> graph[N];
long long par[N][LN], dep[N];
long long parent[N];
long long ans[N];
void dfs(long long node, long long p = -1) {
  par[node][0] = p;
  if (p == -1)
    dep[node] = 0;
  else
    dep[node] = dep[p] + 1;
  for (auto x : g[node])
    if (x != p) dfs(x, node);
}
void dfs1(long long node, long long par = -1) {
  sz[node] = 1;
  for (auto x : g[node])
    if ((!used[x]) && x != par) {
      dfs1(x, node);
      sz[node] += sz[x];
    }
}
long long dfs2(long long node, long long par = -1) {
  for (auto x : g[node])
    if (x != par && (!used[x]) && sz[x] > (val / 2)) return dfs2(x, node);
  return node;
}
long long decompose(long long node, long long par = -1) {
  dfs1(node);
  val = sz[node];
  long long centroid = dfs2(node);
  if (par != -1) t[centroid].push_back(par), t[par].push_back(centroid);
  used[centroid] = 1;
  for (auto x : g[centroid])
    if (!used[x]) decompose(x, centroid);
  return centroid;
}
void dfs3(long long node, long long par = -1) {
  parent[node] = par;
  for (auto x : t[node])
    if (x != par) dfs3(x, node);
}
long long lca(long long a, long long b) {
  if (dep[a] > dep[b]) swap(a, b);
  long long z = dep[b] - dep[a];
  for (long long i = LN - 1; i >= 0; i--)
    if (1LL << i & z) b = par[b][i];
  if (a == b) return a;
  for (long long i = LN - 1; i >= 0; i--)
    if (par[a][i] != par[b][i]) a = par[a][i], b = par[b][i];
  return par[a][0];
}
long long dist(long long u, long long v) {
  long long x = lca(u, v);
  return dep[u] + dep[v] - 2 * dep[x];
}
long long root;
void update(long long node) {
  long long x = node;
  ans[node] = 0;
  while (x != root) {
    x = parent[x];
    ans[x] = min(ans[x], dist(node, x));
  }
}
long long query(long long node) {
  long long res = ans[node];
  long long x = node;
  while (x != root) {
    x = parent[x];
    res = min(res, ans[x] + dist(x, node));
  }
  return res;
}
void solve() {
  I(n);
  I(q);
  long long u, v;
  for (long long i = 1; i <= n - 1; i++) {
    I(u);
    I(v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1);
  root = decompose(1);
  dfs3(root);
  for (long long i = 1; i < LN; i++)
    for (long long j = 1; j <= n; j++)
      if (par[j][i - 1] != -1) par[j][i] = par[par[j][i - 1]][i - 1];
  for (long long i = 1; i <= n; i++) ans[i] = 1e9;
  update(1);
  while (q--) {
    I(u);
    I(v);
    if (u == 1)
      update(v);
    else
      cout << query(v) << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
