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;
using ull = unsigned long long;
using ll = long long;
int BLOCK_SIZE = 317;
int n, m;
pair<int, int> t[800005];
int h[100005], fst[100005];
vector<int> g[100005];
int dst[100005], cl[100005];
vector<int> ord, ordh;
int lst_sz;
void bfs() {
  queue<int> q;
  fill(dst + 1, dst + 1 + n, 1e9);
  for (int i = 1; i <= n; ++i) {
    if (cl[i] == 1) {
      q.push(i);
      dst[i] = 0;
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : g[u]) {
      if (dst[v] > dst[u] + 1) {
        dst[v] = dst[u] + 1;
        q.push(v);
      }
    }
  }
}
void dfs(int u, int p = -1) {
  ord.push_back(u), ordh.push_back(h[u]);
  for (auto v : g[u]) {
    if (v != p) {
      h[v] = h[u] + 1;
      dfs(v, u);
      ord.push_back(u), ordh.push_back(h[u]);
    }
  }
}
void build(int v, int vl, int vr) {
  if (vl == vr) {
    t[v] = {ordh[vl], ord[vl]};
    return;
  }
  int m = (vl + vr) >> 1;
  build(2 * v, vl, m);
  build(2 * v + 1, m + 1, vr);
  t[v] = min(t[2 * v], t[2 * v + 1]);
}
pair<int, int> get(int v, int vl, int vr, int l, int r) {
  if (r < vl || vr < l) {
    return {1e9, -1};
  }
  if (l <= vl && vr <= r) {
    return t[v];
  }
  int m = (vl + vr) >> 1;
  return min(get(2 * v, vl, m, l, r), get(2 * v + 1, m + 1, vr, l, r));
}
int lca(int u, int v) {
  if (fst[v] < fst[u]) {
    swap(u, v);
  }
  return get(1, 0, lst_sz - 1, fst[u], fst[v]).second;
}
int dist(int a, int b) { return h[a] + h[b] - 2 * h[lca(a, b)]; }
void init() {
  dfs(1);
  lst_sz = (int)ord.size();
  fill(fst + 1, fst + 1 + n, -1);
  for (int i = 0; i < lst_sz; ++i) {
    if (fst[ord[i]] == -1) {
      fst[ord[i]] = i;
    }
  }
  build(1, 0, lst_sz - 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0, u, v; i < n - 1; ++i) {
    cin >> u >> v;
    g[u].push_back(v), g[v].push_back(u);
  }
  cl[1] = 1;
  init();
  vector<int> vs;
  BLOCK_SIZE = sqrt(1e5);
  for (int i = 0, t, v; i < m; ++i) {
    if (i % BLOCK_SIZE == 0) {
      vs.clear();
      bfs();
    }
    cin >> t >> v;
    if (t == 1) {
      cl[v] = 1;
      vs.push_back(v);
    } else {
      int ans = dst[v];
      for (auto x : vs) {
        ans = min(ans, dist(v, x));
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
