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;
template <class T>
int size(const T &x) {
  return x.size();
}
const int INF = 1000000000;
int jmp[100100][50], path[100100][50];
int shortest[100100];
struct centroid_decomposition {
  int n;
  vector<vector<int> > adj;
  vector<int> subsize, seph;
  centroid_decomposition(int _n) : n(_n), adj(n), subsize(n), seph(n) {}
  void add_edge(int a, int b) {
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int dfs(int u, int p) {
    subsize[u] = 1;
    for (__typeof(0) i = (0); i < (size(adj[u])); ++i) {
      if (adj[u][i] == p) continue;
      subsize[u] += dfs(adj[u][i], u);
    }
    return subsize[u];
  }
  int curlen;
  void makepaths(int sep, int u, int p) {
    jmp[u][seph[sep]] = sep;
    path[u][seph[sep]] = curlen;
    curlen++;
    int bad = -1;
    for (__typeof(0) i = (0); i < (size(adj[u])); ++i) {
      if (adj[u][i] == p) {
        bad = i;
        continue;
      }
      makepaths(sep, adj[u][i], u);
    }
    if (p == sep) swap(adj[u][bad], adj[u].back()), adj[u].pop_back();
    curlen--;
  }
  int separate(int h, int u) {
    dfs(u, -1);
    int sep = u, p = -1;
    while (true) {
      int nxt = -1;
      for (__typeof(0) i = (0); i < (size(adj[sep])); ++i) {
        if (adj[sep][i] == p) continue;
        if (subsize[adj[sep][i]] > subsize[u] / 2) {
          nxt = adj[sep][i];
          break;
        }
      }
      if (nxt == -1) {
        break;
      }
      p = sep;
      sep = nxt;
    }
    seph[sep] = h;
    curlen = 0;
    makepaths(sep, sep, -1);
    for (__typeof(0) i = (0); i < (size(adj[sep])); ++i) {
      int nxt = adj[sep][i];
      assert(find(adj[nxt].begin(), adj[nxt].end(), sep) == adj[nxt].end());
      separate(h + 1, nxt);
    }
    return sep;
  }
  void build() { separate(0, 0); }
  void paint(int u) {
    for (__typeof(0) h = (0); h < (seph[u] + 1); ++h) {
      shortest[jmp[u][h]] = min(shortest[jmp[u][h]], path[u][h]);
    }
  }
  int closest(int u) {
    int mn = INF;
    for (__typeof(0) h = (0); h < (seph[u] + 1); ++h) {
      mn = min(mn, path[u][h] + shortest[jmp[u][h]]);
    }
    return mn;
  }
};
int main() {
  int n, m;
  scanf("%d %d\n", &n, &m);
  centroid_decomposition cd(n);
  for (__typeof(0) i = (0); i < (n); ++i) shortest[i] = INF;
  for (__typeof(0) i = (0); i < (n - 1); ++i) {
    int a, b;
    scanf("%d %d\n", &a, &b);
    a--, b--;
    cd.add_edge(a, b);
  }
  cd.build();
  cd.paint(0);
  for (__typeof(0) i = (0); i < (m); ++i) {
    int a, b;
    scanf("%d %d\n", &a, &b);
    b--;
    if (a == 1) {
      cd.paint(b);
    } else {
      printf("%d\n", cd.closest(b));
    }
  }
  return 0;
}
