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 = 1e5 + 5, LN = 20;
vector<int> adj[N], decomp[N], dist[N];
int sz[N], orignal_p[LN][N], p[N], h[N];
multiset<int> S[N];
bool visited[N], color[N];
void myParent(int u, int prev, int height) {
  orignal_p[0][u] = prev;
  h[u] = height;
  for (int i = 0; i < adj[u].size(); i++)
    if (adj[u][i] != prev) myParent(adj[u][i], u, height + 1);
}
void dfs(int u, int prev) {
  sz[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v != prev and visited[v] == false) dfs(v, u), sz[u] += sz[v];
  }
}
int calc(int u, int prev, int n) {
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v != prev and visited[v] == false and sz[v] > n / 2)
      return calc(v, u, n);
  }
  return u;
}
void centroid(int u, int prev) {
  dfs(u, -1);
  u = calc(u, -1, sz[u]);
  visited[u] = true;
  decomp[prev].push_back(u);
  for (int i = 0; i < adj[u].size(); i++)
    if (!visited[adj[u][i]]) centroid(adj[u][i], u);
}
void print_tree(int x) {
  cout << x << " opened" << endl;
  for (int i = 0; i < decomp[x].size(); i++) print_tree(decomp[x][i]);
  cout << x << " closed" << endl;
}
void myParentCentroid(int u, int prev) {
  p[u] = prev;
  for (int i = 0; i < decomp[u].size(); i++) myParentCentroid(decomp[u][i], u);
}
int lca(int a, int b) {
  if (h[a] < h[b]) swap(a, b);
  int remain = h[a] - h[b], ans = 0;
  for (int i = 0; i < LN; i++)
    if (remain & (1 << i)) a = orignal_p[i][a], ans += (1 << i);
  if (a == b) return ans;
  for (int i = LN - 1; i >= 0; i--) {
    if (orignal_p[i][a] != orignal_p[i][b])
      a = orignal_p[i][a], b = orignal_p[i][b], ans += (1 << (i + 1));
  }
  return (ans + 2);
}
void update(int u) {
  color[u] = !color[u];
  int yo = u, cntr = 0;
  while (yo) {
    if (color[u])
      S[yo].insert(dist[u][cntr]);
    else
      S[yo].erase(dist[u][cntr]);
    cntr++;
    yo = p[yo];
  }
}
int query(int u) {
  int yo = u, cntr = 0, ans = INT_MAX;
  while (yo) {
    if (!S[yo].empty()) ans = min(ans, dist[u][cntr] + (*S[yo].begin()));
    cntr++;
    yo = p[yo];
  }
  return (ans == INT_MAX ? -1 : ans);
}
int main() {
  int n, u, v, q, type;
  scanf("%d %d", &n, &q);
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  myParent(1, 0, 0);
  for (int i = 1; i < LN; i++)
    for (int j = 1; j <= n; j++)
      orignal_p[i][j] = orignal_p[i - 1][orignal_p[i - 1][j]];
  centroid(1, 0);
  int root = decomp[0][0];
  myParentCentroid(root, 0);
  for (int i = 1; i <= n; i++) {
    int yo = i;
    while (yo) {
      dist[i].push_back(lca(i, yo));
      yo = p[yo];
    }
  }
  update(1);
  while (q--) {
    scanf("%d %d", &type, &u);
    if (type == 1)
      update(u);
    else
      cout << query(u) << '\n';
  }
}
