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>
#pragma GCC optimize "03"
using namespace std;
const long long int inf = 1e15;
const long long int MOD = 1e9 + 7;
const long long int N = 1e5 + 5;
const long long int LOGN = 18;
vector<long long int> g[N];
long long int dep[N], dp[LOGN][N];
bool mark[N];
long long int sz[N], par[N];
long long int ans[N];
void dfs2(long long int u, long long int p) {
  for (auto v : g[u]) {
    if (v == p) continue;
    dep[v] = dep[u] + 1;
    dp[0][v] = u;
    dfs2(v, u);
  }
}
void preprocess(long long int n) {
  dep[1] = 0;
  dp[0][1] = 1;
  dfs2(1, 0);
  for (long long int k = 1; k < LOGN; k++) {
    for (long long int i = 1; i <= n; i++) {
      dp[k][i] = dp[k - 1][dp[k - 1][i]];
    }
  }
}
long long int lca(long long int u, long long int v) {
  if (dep[u] > dep[v]) swap(u, v);
  long long int d = dep[v] - dep[u];
  for (long long int k = LOGN - 1; k >= 0; k--) {
    if (d & (1 << k)) v = dp[k][v];
  }
  if (u == v) return u;
  for (long long int k = LOGN - 1; k >= 0; k--) {
    if (dp[k][u] != dp[k][v]) u = dp[k][u], v = dp[k][v];
  }
  return dp[0][u];
}
long long int dis(long long int a, long long int b) {
  return dep[a] + dep[b] - 2 * dep[lca(a, b)];
}
long long int dfs(long long int u, long long int p) {
  sz[u] = 1;
  for (auto v : g[u]) {
    if (v == p || mark[v]) continue;
    sz[u] += dfs(v, u);
  }
  return sz[u];
}
long long int centroid(long long int u, long long int p, long long int n) {
  for (auto v : g[u]) {
    if (v == p || mark[v]) continue;
    if (sz[v] > n / 2) return centroid(v, u, n);
  }
  return u;
}
void decompose(long long int u, long long int p) {
  long long int n = dfs(u, p);
  long long int c = centroid(u, p, n);
  mark[c] = 1;
  if (p == 0) p = c;
  par[c] = p;
  for (auto v : g[c]) {
    if (!mark[v]) decompose(v, c);
  }
}
void update(long long int u) {
  ans[u] = 0;
  long long int v = u;
  while (true) {
    ans[v] = min(ans[v], dis(u, v));
    if (v == par[v]) break;
    v = par[v];
  }
}
long long int query(long long int u) {
  long long int val = inf;
  long long int v = u;
  while (true) {
    val = min(val, ans[v] + dis(u, v));
    if (v == par[v]) break;
    v = par[v];
  }
  return val;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < n - 1; i++) {
    long long int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  preprocess(n);
  decompose(1, 0);
  for (long long int i = 1; i <= n; i++) ans[i] = inf;
  update(1);
  for (long long int i = 0; i < m; i++) {
    long long int t, a;
    cin >> t >> a;
    if (t == 1)
      update(a);
    else
      cout << query(a) << '\n';
  }
  return 0;
}
