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<vector<int> > Adj;
struct CeDe : unordered_set<int> {
  vector<int> P, cnt;
  CeDe(int n) {
    P.resize(n), cnt.resize(n);
    build(0, -1);
  }
  void build(int u, int p) {
    int sz = dfs(u, u), ct = dfs(u, u, sz);
    if (p == -1) p = ct;
    P[ct] = p;
    insert(ct);
    for (auto v : Adj[ct])
      if (find(v) == end()) build(v, ct);
  }
  int dfs(int u, int p) {
    cnt[u] = 1;
    for (auto v : Adj[u])
      if (v != p and find(v) == end()) cnt[u] += dfs(v, u);
    return cnt[u];
  }
  int dfs(int u, int p, int sz) {
    for (auto v : Adj[u])
      if (v != p and find(v) == end())
        if (cnt[v] > sz / 2) return dfs(v, u, sz);
    return u;
  }
  int operator[](int u) { return P[u]; }
};
vector<int> H, tin, tout;
vector<vector<int> > up;
int timer = 0;
void dfs(int u, int p, int h) {
  tin[u] = timer++;
  H[u] = h;
  up[u][0] = p;
  for (int i = 1; i < 20; i++) up[u][i] = up[up[u][i - 1]][i - 1];
  for (auto v : Adj[u])
    if (v != p) dfs(v, u, h + 1);
  tout[u] = timer++;
  return;
}
bool IsAnc(int u, int v) { return tin[u] <= tin[v] and tout[v] <= tout[u]; }
int lca(int u, int v) {
  if (IsAnc(u, v)) return u;
  if (IsAnc(v, u)) return v;
  for (int i = 19; i >= 0; i--)
    if (!IsAnc(up[u][i], v)) u = up[u][i];
  return up[u][0];
}
int dist(int u, int v) {
  int c = lca(u, v);
  return abs(H[u] - H[c]) + abs(H[v] - H[c]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N, Q;
  cin >> N >> Q;
  Adj.resize(N);
  H.resize(N), tin.resize(N), tout.resize(N);
  up.resize(N, vector<int>(20));
  for (int x = 0; x < N - 1; x++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    Adj[u].push_back(v);
    Adj[v].push_back(u);
  }
  CeDe K(N);
  dfs(0, 0, 0);
  vector<int> Col(N, 999999999);
  for (int u = 0, i = 0; i < 20; i++) {
    Col[u] = dist(u, 0);
    u = K[u];
  }
  while (Q--) {
    int t, v;
    cin >> t >> v;
    v--;
    if (t == 1) {
      int u = v;
      for (int i = 0; i < 20; i++) {
        Col[u] = min(Col[u], dist(u, v));
        u = K[u];
      }
    } else {
      int ans = 999999999;
      int u = v;
      for (int i = 0; i < 20; i++) {
        ans = min(ans, Col[u] + dist(u, v));
        u = K[u];
      }
      cout << ans << endl;
    }
  }
  return 0;
}
