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 MAX = 1e5 + 5;
const int LOG = 18;
const int INF = 1e9;
template <int MAXN, int MAXLG>
struct centroidDecomp {
  vector<int> adj[MAXN];
  int sz[MAXN];
  int cpar[MAXN];
  int cdist[MAXN];
  bool vis[MAXN];
  int L[MAXLG][MAXN];
  int depth[MAXN];
  void addEdge(int u, int v) {
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
  }
  void dfs(int n, int p) {
    depth[n] = depth[p] + 1;
    L[0][n] = p;
    for (int i = 0; i < MAXLG - 1; i++) L[i + 1][n] = L[i][L[i][n]];
    for (int v : adj[n])
      if (v != p) {
        dfs(v, n);
      }
  }
  int lca(int u, int v) {
    if (depth[u] < depth[v]) swap(u, v);
    for (int i = MAXLG - 1; i >= 0; i--) {
      if (depth[u] - (1 << i) >= depth[v]) u = L[i][u];
    }
    for (int i = MAXLG - 1; i >= 0; i--) {
      if (L[i][u] != L[i][v]) u = L[i][u], v = L[i][v];
    }
    return u == v ? u : L[0][u];
  }
  int dist(int u, int v) { return depth[u] + depth[v] - 2 * depth[lca(u, v)]; }
  void dfs_sz(int n, int p = -1) {
    sz[n] = 1;
    for (int v : adj[n])
      if (v != p && !vis[v]) {
        dfs_sz(v, n);
        sz[n] += sz[v];
      }
  }
  int centroid(int n) {
    dfs_sz(n);
    int num = sz[n];
    int p = -1;
    do {
      int nxt = -1;
      for (int v : adj[n])
        if (!vis[v] && v != p) {
          if (2 * sz[v] > num) nxt = v;
        }
      p = n, n = nxt;
    } while (~n);
    return p;
  }
  void centroid_decomp(int n, int p = -1) {
    int c = centroid(n);
    vis[c] = true;
    cpar[c] = p;
    for (int v : adj[c])
      if (!vis[v]) {
        centroid_decomp(v, c);
      }
  }
};
int n, m;
centroidDecomp<MAX, LOG> cd;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    cd.addEdge(u, v);
  }
  cd.dfs(0, 0);
  cd.centroid_decomp(0);
  for (int i = 0; i < n; i++) cd.cdist[i] = cd.dist(0, i);
  for (int i = 0; i < m; i++) {
    int t, v;
    cin >> t >> v;
    v--;
    if (t == 1) {
      for (int n = v; ~n; n = cd.cpar[n])
        cd.cdist[n] = min(cd.cdist[n], cd.dist(n, v));
    } else {
      int ans = cd.cdist[v];
      for (int n = v; ~n; n = cd.cpar[n])
        ans = min(ans, cd.cdist[n] + cd.dist(n, v));
      cout << ans << endl;
      ;
    }
  }
  return 0;
}
