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("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
vector<int> h, order, d, used, first, sz;
vector<vector<int> > g;
int N;
void dfs(int v, int from) {
  first[v] = order.size();
  order.push_back(v);
  for (int to : g[v]) {
    if (to != from) {
      h[to] = h[v] + 1;
      dfs(to, v);
      order.push_back(v);
    }
  }
}
void build(int v, int tl, int tr) {
  if (tl == tr) {
    d[v] = order[tl];
    return;
  }
  int tm = (tl + tr) / 2;
  build(2 * v, tl, tm);
  build(2 * v + 1, tm + 1, tr);
  if (h[d[2 * v]] < h[d[2 * v + 1]])
    d[v] = d[2 * v];
  else
    d[v] = d[2 * v + 1];
}
int getmin(int v, int tl, int tr, int l, int r) {
  if (l > r) return -1;
  if (l == tl && r == tr) return d[v];
  int tm = (tl + tr) / 2;
  int a = getmin(2 * v, tl, tm, l, min(r, tm));
  int b = getmin(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
  if (a == -1) return b;
  if (b == -1) return a;
  if (h[a] > h[b])
    return b;
  else
    return a;
}
int lca(int u, int v) {
  return getmin(1, 0, N - 1, min(first[u], first[v]), max(first[u], first[v]));
}
int find_dist(int u, int v) { return h[u] + h[v] - 2 * h[lca(u, v)]; }
void get_sizes(int v, int from, vector<int>& sz) {
  sz[v] = 1;
  for (int to : g[v])
    if (to != from && !used[to]) {
      get_sizes(to, v, sz);
      sz[v] += sz[to];
    }
}
int centroid(int v, int from, int all, vector<int>& sz) {
  for (int to : g[v])
    if (to != from && !used[to] && sz[to] > all / 2)
      return centroid(to, v, all, sz);
  return v;
}
void centroid_decomposition(int v, int anc, vector<int>& cd) {
  get_sizes(v, -1, sz);
  int c = centroid(v, -1, sz[v], sz);
  used[c] = 1;
  cd[c] = anc;
  for (int to : g[c])
    if (!used[to]) centroid_decomposition(to, c, cd);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  g.resize(n);
  sz.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u - 1].push_back(v - 1);
    g[v - 1].push_back(u - 1);
  }
  h.resize(n);
  used.resize(n);
  first.resize(n);
  dfs(0, -1);
  N = order.size();
  d.resize(4 * N);
  build(1, 0, N - 1);
  vector<int> cd(n);
  centroid_decomposition(0, -1, cd);
  vector<set<int> > s(n);
  for (int u = 0; u != -1; u = cd[u]) s[u].insert(find_dist(u, 0));
  while (m--) {
    int t, v;
    cin >> t >> v;
    --v;
    if (t == 1)
      for (int u = v; u != -1; u = cd[u]) s[u].insert(find_dist(u, v));
    else {
      int dist = n;
      for (int u = v; u != -1; u = cd[u])
        if (!s[u].empty()) dist = min(dist, find_dist(u, v) + *s[u].begin());
      cout << dist << "\n";
    }
  }
  return 0;
}
