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;
int n, q, nodes;
vector<vector<int>> adj, tree, sp;
vector<int> subsize, is_cent, par, close, idx2node, node2idx, lg{-1}, depth;
void init() {
  adj.resize(n);
  tree.resize(n);
  subsize.resize(n);
  is_cent.resize(n);
  par.resize(n);
  close.resize(n);
  node2idx.resize(n);
  depth.resize(n);
}
void dfs(int u, int p = -1) {
  subsize[u] = 1;
  ++nodes;
  for (int v : adj[u]) {
    if (v ^ p && !is_cent[v]) {
      dfs(v, u);
      subsize[u] += subsize[v];
    }
  }
}
int centroid(int u, int p) {
  bool is = nodes - subsize[u] <= nodes / 2;
  int heavy = -1;
  for (int v : adj[u]) {
    if (v ^ p && !is_cent[v]) {
      is &= subsize[v] <= nodes / 2;
      if (heavy == -1 || subsize[v] > subsize[heavy]) {
        heavy = v;
      }
    }
  }
  return is ? u : centroid(heavy, u);
}
int centroid(int u) {
  nodes = 0;
  dfs(u);
  int cent = centroid(u, -1);
  is_cent[cent] = 1;
  return cent;
}
int decompose(int u = 0) {
  int cent_tree = centroid(u);
  for (int v : adj[cent_tree]) {
    if (!is_cent[v]) {
      int cent_subtree = decompose(v);
      tree[cent_tree].push_back(cent_subtree);
      tree[cent_subtree].push_back(cent_tree);
    }
  }
  return cent_tree;
}
void dfs2(int u, int p = -1) {
  par[u] = p;
  for (int v : tree[u]) {
    if (v ^ p) {
      dfs2(v, u);
    }
  }
}
void dfs3(int u = 0, int p = -1) {
  node2idx[u] = idx2node.size();
  idx2node.push_back(u);
  for (int v : adj[u]) {
    if (v ^ p) {
      depth[v] = depth[u] + 1;
      dfs3(v, u);
      idx2node.push_back(u);
    }
  }
}
void build() {
  int n = idx2node.size();
  for (int i = 1; i <= n; ++i) {
    lg.push_back(lg.back() + !(i & (i - 1)));
  }
  sp.resize(lg[n] + 1, vector<int>(n));
  iota(sp[0].begin(), sp[0].end(), 0);
  for (int i = 1; i < lg[n] + 1; ++i) {
    for (int j = 0; j < n - (1 << i) + 1; ++j) {
      int a = sp[i - 1][j];
      int b = sp[i - 1][j + (1 << i - 1)];
      sp[i][j] = depth[idx2node[a]] < depth[idx2node[b]] ? a : b;
    }
  }
}
int query(int a, int b) {
  int k = lg[b - a + 1];
  a = sp[k][a];
  b = sp[k][b - (1 << k) + 1];
  return depth[idx2node[a]] < depth[idx2node[b]] ? a : b;
}
int lca(int u, int v) {
  u = node2idx[u];
  v = node2idx[v];
  if (u > v) {
    swap(u, v);
  }
  return idx2node[query(u, v)];
}
int dist(int u, int v) { return depth[u] + depth[v] - 2 * depth[lca(u, v)]; }
void paint(int u) {
  int v = u;
  while (~u) {
    close[u] = dist(u, v) < dist(u, close[u]) ? v : close[u];
    u = par[u];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> q;
  init();
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v, --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int root = decompose();
  dfs2(root);
  dfs3();
  build();
  paint(0);
  while (q--) {
    int t, u;
    cin >> t >> u, --u;
    if (t == 1) {
      paint(u);
    } else {
      int ans = 1e9, c = 0, v = u;
      while (~u) {
        ans = min(ans, dist(v, close[u]));
        u = par[u];
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
