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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e5 + 5;
vector<int> adj[maxn];
int N, Q;
int sz[maxn];
bool vis[maxn];
int up[maxn];
int ans[maxn];
void findsz(int u, int p = -1) {
  sz[u] = 1;
  for (int v : adj[u]) {
    if (v != p && !vis[v]) {
      findsz(v, u);
      sz[u] += sz[v];
    }
  }
}
int find_cen(int u, int p, int size) {
  for (int v : adj[u]) {
    if (v != p && !vis[v]) {
      if (sz[v] > size / 2) {
        return find_cen(v, u, size);
      }
    }
  }
  return u;
}
void centroid(int root = 1, int p = -1) {
  findsz(root, root);
  int k = find_cen(root, root, sz[root]);
  up[k] = p;
  vis[k] = 1;
  for (int u : adj[k]) {
    if (!vis[u]) {
      centroid(u, k);
    }
  }
}
int cnt[maxn];
int p[maxn][20];
void dfs(int u = 1, int v = 0) {
  p[u][0] = v;
  for (auto &x : adj[u]) {
    if (x == v) continue;
    cnt[x] = cnt[u] + 1;
    dfs(x, u);
  }
}
int lca(int x, int y) {
  if (cnt[x] < cnt[y]) swap(x, y);
  for (int k = 19; k >= 0; --k) {
    if (cnt[p[x][k]] >= cnt[y]) {
      x = p[x][k];
    }
  }
  if (x == y) return x;
  for (int k = 19; k >= 0; --k) {
    if (p[x][k] != p[y][k]) {
      x = p[x][k];
      y = p[y][k];
    }
  }
  return p[x][0];
}
int D(int u, int v) {
  int Lca = lca(u, v);
  return cnt[u] - cnt[Lca] + cnt[v] - cnt[Lca];
}
void Init_lca(void) {
  cnt[1] = 1;
  dfs();
  for (int k = 1; (1 << k) <= N; k++) {
    for (int i = 1; i <= N; ++i) {
      p[i][k] = p[p[i][k - 1]][k - 1];
    }
  }
}
signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> Q;
  for (int i = 1, u, v; i < N; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= N; ++i) ans[i] = 1e8;
  centroid();
  Init_lca();
  int u, v;
  u = v = 1;
  while (u != -1) {
    ans[u] = min(ans[u], D(u, v));
    u = up[u];
  }
  while (Q--) {
    int type;
    cin >> type >> v;
    if (type == 1) {
      u = v;
      while (u != -1) {
        ans[u] = min(ans[u], D(u, v));
        u = up[u];
      }
    } else {
      int res = 1e8;
      u = v;
      while (u != -1) {
        res = min(res, ans[u] + D(u, v));
        u = up[u];
      }
      ans[v] = res;
      cout << res << '\n';
    }
  }
}
