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;
const int N = 100 * 1000 + 100;
const int LG = 17;
const int SQ = 317;
const int oo = 1e9;
int n, m;
vector<int> g[N];
int par[LG][N];
int d[N];
bool mark[N];
queue<int> q;
pair<int, int> Q[N];
int h[N];
void dfs(int v, int p) {
  par[0][v] = p;
  for (int u : g[v]) {
    if (u == p) continue;
    h[u] = h[v] + 1;
    dfs(u, v);
  }
}
int lca(int x, int y) {
  if (h[y] < h[x]) swap(x, y);
  for (int i = LG; i--;)
    if (par[i][y] != -1 && h[par[i][y]] >= h[x]) y = par[i][y];
  if (x == y) return x;
  for (int i = LG; i--;)
    if (par[i][x] != par[i][y]) x = par[i][x], y = par[i][y];
  return par[0][x];
}
void bfs() {
  memset(d, -1, sizeof d);
  for (int i = 0; i < n; ++i)
    if (mark[i]) q.push(i), d[i] = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int y : g[x])
      if (d[y] == -1) q.push(y), d[y] = d[x] + 1;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  memset(par, -1, sizeof par);
  mark[0] = 1;
  cin >> n >> m;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(0, -1);
  for (int i = 1; i < LG; ++i)
    for (int j = 0; j < n; ++j)
      if (par[i - 1][j] != -1) par[i][j] = par[i - 1][par[i - 1][j]];
  for (int i = 0; i < m; ++i) {
    if (!(i % SQ)) bfs();
    int t, x;
    cin >> t >> x;
    x--;
    Q[i] = make_pair(t, x);
    if (t == 1)
      mark[x] = 1;
    else {
      int k = d[x];
      if (k == -1) k = oo;
      for (int j = i - i % SQ; j < i; ++j)
        if (Q[j].first == 1)
          k = min(k, h[Q[j].second] + h[x] - 2 * h[lca(x, Q[j].second)]);
      cout << k << "\n";
    }
  }
  return 0;
}
