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;
long long t, n, u, v, m, q, r, ql, qr, k, l, s, x, y, d;
const int N = 1e5 + 500;
const int LN = 20;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57LL;
const bool JUDGE = false;
vector<int> adj[N];
bool centered[N];
int sz[N], P[N], ans[N], L[N][LN], D[N];
bool ft = true;
void dfs(int v, int p) {
  sz[v] = 1;
  if (ft) L[v][0] = p;
  if (ft) D[v] = D[p] + 1;
  for (int i = 0; i < adj[v].size(); ++i) {
    int u = adj[v][i];
    if (centered[u] || u == p) continue;
    dfs(u, v);
    sz[v] += sz[u];
  }
}
int find_cent(int v, int n) {
  dfs(v, 0);
  if (n == 0) return 0;
  if (n == 1) return v;
  int p = 0;
  for (int i = 0; i < adj[v].size(); ++i) {
    int u = adj[v][i];
    if (u == p || centered[u]) continue;
    if (sz[u] > n / 2) {
      p = v;
      v = u;
      i = -1;
      continue;
    }
  }
  centered[v] = true;
  for (int i = 0; i < adj[v].size(); ++i) {
    int u = adj[v][i];
    int x;
    if (centered[u]) continue;
    if (u == p) {
      x = find_cent(u, n - sz[v]);
    } else
      x = find_cent(u, sz[u]);
    P[x] = v;
  }
  return v;
}
int lca(int u, int v) {
  if (D[u] > D[v]) swap(u, v);
  int diff = D[v] - D[u];
  for (int i = 0; i < LN; ++i) {
    if (diff & (1 << i)) v = L[v][i];
  }
  if (u == v) return u;
  for (int i = LN - 1; i >= 0; --i) {
    if (L[v][i] != L[u][i]) {
      u = L[u][i];
      v = L[v][i];
    }
  }
  return L[u][0];
}
inline int dist(int u, int v) { return D[v] + D[u] - 2 * D[lca(u, v)]; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  if (JUDGE) {
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  }
  cin >> n >> m;
  for (int i = 0; i < n - 1; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0);
  ft = false;
  P[0] = find_cent(1, n);
  for (int i = 0; i <= n; ++i) ans[i] = INT_MAX;
  for (int i = 1; i < LN; ++i) {
    for (int j = 1; j <= n; ++j) L[j][i] = L[L[j][i - 1]][i - 1];
  }
  int x = 1;
  v = 1;
  while (x) {
    ans[x] = min(ans[x], dist(v, x));
    x = P[x];
  }
  while (m--) {
    int id;
    cin >> id;
    if (id == 1) {
      cin >> v;
      int x = v;
      while (x) {
        ans[x] = min(ans[x], dist(v, x));
        x = P[x];
      }
    } else {
      cin >> v;
      int x = v;
      int Ans = INT_MAX;
      while (x) {
        if (ans[x] == INT_MAX) {
          x = P[x];
          continue;
        }
        Ans = min(Ans, ans[x] + dist(x, v));
        x = P[x];
      }
      cout << Ans << '\n';
    }
  }
  return 0;
}
