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;
vector<int> adj[100001];
vector<int> centroidTree[100005 + 1];
int centroidMarked[100005 + 1];
int par[100005 + 1][21];
int level[100005 + 1];
int cpar[100005 + 1];
void dfs(int s, int p) {
  level[s] = level[p] + 1;
  par[s][0] = p;
  for (auto it : adj[s])
    if (it != p) dfs(it, s);
}
void preprocess(int n) {
  memset(par, -1, sizeof(par));
  dfs(1, 0);
  for (int i = 1; i < 21; i++) {
    for (int j = 1; j <= n; j++) {
      if (par[j][i - 1] != -1) par[j][i] = par[par[j][i - 1]][i - 1];
    }
  }
}
int lca(int u, int v) {
  if (level[v] < level[u]) swap(u, v);
  int diff = level[v] - level[u];
  for (int i = 0; i < 21; i++)
    if ((diff >> i) & 1) v = par[v][i];
  if (u == v) return u;
  for (int i = 20; i >= 0; i--)
    if (par[u][i] != par[v][i]) {
      u = par[u][i];
      v = par[v][i];
    }
  return par[u][0];
}
int dist(int u, int v) { return level[u] + level[v] - 2 * level[lca(u, v)]; }
int setsubtreeSize(int s, bool vis[], int subtree[], int *n) {
  if (vis[s] or centroidMarked[s]) return 0;
  vis[s] = true;
  *n += 1;
  subtree[s] = 1;
  for (int i = 0; i < adj[s].size(); i++) {
    subtree[s] += setsubtreeSize(adj[s][i], vis, subtree, n);
  }
  return subtree[s];
}
int findCentroid(int s, int n, int subtree[], bool vis[]) {
  bool isCentroid = true;
  vis[s] = true;
  int hC = 0;
  for (int i = 0; i < adj[s].size(); i++) {
    int e = adj[s][i];
    if (!vis[e]) {
      if (subtree[e] > n / 2) isCentroid = false;
      if (hC == 0 || subtree[e] > subtree[hC]) hC = e;
    }
  }
  if (isCentroid and subtree[s] > n / 2) return s;
  return findCentroid(hC, n, subtree, vis);
}
int getCentroid(int s) {
  bool vis[100005 + 1];
  int subtree[100005 + 1];
  memset(vis, false, sizeof(vis));
  memset(subtree, 0, sizeof(subtree));
  int n = 0;
  setsubtreeSize(s, vis, subtree, &n);
  memset(vis, false, sizeof(vis));
  int centroid = findCentroid(s, n, subtree, vis);
  centroidMarked[centroid] = true;
  return centroid;
}
int decomposeTree(int s, int p) {
  int cent = getCentroid(s);
  cpar[cent] = p;
  for (int i = 0; i < adj[cent].size(); i++) {
    if (!centroidMarked[adj[cent][i]]) {
      int cent_sub = decomposeTree(adj[cent][i], cent);
      centroidTree[cent].push_back(cent_sub);
      centroidTree[cent_sub].push_back(cent);
    }
  }
  return cent;
}
int ans[100005 + 1];
void update(int u) {
  int x = u;
  while (x != 0) {
    ans[x] = min(ans[x], dist(x, u));
    x = cpar[x];
  }
}
int query(int u) {
  int ret = 1e8;
  int x = u;
  while (x != 0) {
    ret = min(ret, ans[x] + dist(x, u));
    x = cpar[x];
  }
  return ret;
}
int main(int argc, char const *argv[]) {
  memset(centroidMarked, false, sizeof(centroidMarked));
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  preprocess(n);
  decomposeTree(1, 0);
  for (int i = 0; i < n + 1; i++) ans[i] = 1e8;
  update(1);
  while (q--) {
    int qt, u;
    cin >> qt >> u;
    if (qt == 1)
      update(u);
    else
      cout << query(u) << endl;
  }
  return 0;
}
