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>
const int INF = 1e18;
const int inf = 1e9;
const int MAXN = 3e5 + 200;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
using namespace std;
int level[MAXN], parent[MAXN], tin[MAXN], tout[MAXN], dp[MAXN];
int up[MAXN][20];
vector<int> g[MAXN];
int n, m, timer;
int ans[MAXN];
bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }
void dfs_for_lcp(int v, int p) {
  dp[v] = dp[p] + 1;
  tin[v] = ++timer;
  up[v][0] = p;
  for (int i = 1; i < 20; i++) up[v][i] = up[up[v][i - 1]][i - 1];
  for (int x : g[v])
    if (x != p) dfs_for_lcp(x, v);
  tout[v] = ++timer;
}
int lca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i = 19; i >= 0; i--)
    if (!upper(up[a][i], b)) a = up[a][i];
  return up[a][0];
}
int dfs(int v, int sz, int &center, int p = -1) {
  int sum = 1;
  for (int x : g[v])
    if (level[x] == 0 && x != p) sum += dfs(x, sz, center, v);
  if (center == -1 && (2 * sum >= sz || p == -1)) center = v;
  return sum;
}
void build(int v, int sz, int depth, int last) {
  int center = -1;
  dfs(v, sz, center);
  level[center] = depth;
  parent[center] = last;
  for (int x : g[center])
    if (level[x] == 0) build(x, sz >> 1, depth + 1, center);
}
int dist(int a, int b) {
  int lc = lca(a, b);
  return (dp[a] + dp[b] - 2 * dp[lc]);
}
void update(int v) {
  int V = v;
  while (v != -1) {
    ans[v] = min(ans[v], dist(v, V));
    v = parent[v];
  }
  return;
}
int find_ans(int v) {
  int V = v;
  int res = ans[v];
  while (v != -1) {
    res = min(res, ans[v] + dist(v, V));
    v = parent[v];
  }
  return res;
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs_for_lcp(0, 0);
  build(0, n, 1, -1);
  for (int i = 0; i < n; i++) ans[i] = inf;
  update(0);
  for (int i = 0; i < m; i++) {
    int t, x;
    cin >> t >> x;
    x--;
    if (t == 1)
      update(x);
    else
      cout << find_ans(x) << "\n";
  }
}
int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(0);
  int step;
  step = 1;
  for (int i = 1; i <= step; i++) {
    solve();
  }
}
