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 MX = 1e5 + 5;
int n, m;
vector<int> adj[MX];
queue<pair<int, int>> pendingNodes;
bool markedAsCentroid[MX];
int parentInCentroidTree[MX];
int subtreeSz[MX];
vector<int> adjCentroid[MX];
int currentTreeSz, currentCentroid;
void dfs_findSubtreeSize(int node, int p) {
  subtreeSz[node] = 1;
  for (auto& u : adj[node]) {
    if (u != p && !markedAsCentroid[u]) {
      dfs_findSubtreeSize(u, node);
      subtreeSz[node] += subtreeSz[u];
    }
  }
}
void dfs_findCentroid(int node, int p) {
  currentCentroid = node;
  for (auto& u : adj[node]) {
    if (u == p || markedAsCentroid[u]) continue;
    if (currentTreeSz < subtreeSz[u] * 2) {
      dfs_findCentroid(u, node);
      break;
    }
  }
}
int nextCentroid() {
  while (markedAsCentroid[pendingNodes.front().first]) pendingNodes.pop();
  pair<int, int> treeHead = pendingNodes.front();
  pendingNodes.pop();
  dfs_findSubtreeSize(treeHead.first, -1);
  currentTreeSz = subtreeSz[treeHead.first];
  dfs_findCentroid(treeHead.first, -1);
  markedAsCentroid[currentCentroid] = true;
  parentInCentroidTree[currentCentroid] = treeHead.second;
  return currentCentroid;
}
void buildCentroidTree() {
  pendingNodes.push(make_pair(0, -1));
  while (!pendingNodes.empty()) {
    int centroid = nextCentroid();
    for (auto& u : adj[centroid]) {
      if (!markedAsCentroid[u]) {
        pendingNodes.push({u, centroid});
      }
    }
  }
  for (auto(i) = 0; (i) < (n); (i)++) {
    if (parentInCentroidTree[i] != -1) {
      adjCentroid[i].push_back(parentInCentroidTree[i]);
      adjCentroid[parentInCentroidTree[i]].push_back(i);
    }
  }
}
vector<int> euler;
vector<int> depth;
int dep[MX];
int focc[MX];
int seg[11 * MX];
void euler_dfs(int node, int p, int d) {
  euler.push_back(node);
  depth.push_back(d);
  dep[node] = d;
  if (focc[node] == -1) focc[node] = ((int)(euler).size()) - 1;
  for (auto& u : adj[node]) {
    if (u != p) {
      euler_dfs(u, node, d + 1);
      euler.push_back(node);
      depth.push_back(d);
    }
  }
}
inline void build(int node, int ss, int se) {
  if (ss > se) return;
  if (ss == se)
    seg[node] = ss;
  else {
    int mid = ss + se >> 1;
    build(node * 2 + 1, ss, mid);
    build(node * 2 + 2, mid + 1, se);
    if (depth[seg[node * 2 + 1]] <= depth[seg[node * 2 + 2]]) {
      seg[node] = seg[node * 2 + 1];
    } else {
      seg[node] = seg[node * 2 + 2];
    }
  }
}
inline int query(int node, int ss, int se, int qs, int qe) {
  if (ss > se || qs > se || qe < ss) return -1;
  if (ss >= qs && se <= qe) return seg[node];
  int mid = ss + se >> 1;
  int q1 = query(node * 2 + 1, ss, mid, qs, qe);
  int q2 = query(node * 2 + 2, mid + 1, se, qs, qe);
  if (q1 == -1 && q2 == -1)
    return -1;
  else if (q1 == -1 && q2 != -1)
    return q2;
  else if (q1 != -1 && q2 == -1)
    return q1;
  if (depth[q1] <= depth[q2])
    return q1;
  else
    return q2;
}
inline int LCA(int u, int v) {
  int fu = focc[u], fv = focc[v];
  if (fu > fv) swap(fu, fv);
  return euler[query(0, 0, ((int)(euler).size()) - 1, fu, fv)];
}
inline int dist(int u, int v) { return dep[u] + dep[v] - 2 * dep[LCA(u, v)]; }
int mindist[MX], ans;
int paintedNode, concernedNode;
void climb_update(int node) {
  if (node < 0 || node >= n) return;
  mindist[node] = min(mindist[node], dist(paintedNode, node));
  climb_update(parentInCentroidTree[node]);
}
void climb_query(int node) {
  if (node < 0 || node >= n) return;
  ans = min(ans, mindist[node] + dist(concernedNode, node));
  climb_query(parentInCentroidTree[node]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (auto(i) = 0; (i) < (n - 1); (i)++) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  buildCentroidTree();
  memset(focc, -1, sizeof(focc));
  euler_dfs(0, -1, 0);
  build(0, 0, ((int)(euler).size()) - 1);
  for (auto(i) = 0; (i) < (n); (i)++) mindist[i] = 1e9;
  paintedNode = 0;
  climb_update(0);
  for (auto(i) = 0; (i) < (m); (i)++) {
    int typ, node;
    cin >> typ >> node;
    --node;
    if (typ == 1) {
      paintedNode = node;
      climb_update(node);
    } else {
      concernedNode = node;
      ans = 1e9;
      climb_query(node);
      cout << ans << "\n";
    }
  }
}
