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;
int mod = 1e9 + 7;
const int N = 3e5;
vector<int> g[N], cg[N];
vector<long long> stree[N], contri[N], wt[N];
vector<int> cur;
int part;
int gvis[N], c_par[N];
const int LG = 20;
int a[N], lvl[N], P[N][LG], sz[N];
long long D[N];
void predfs(int u, int par) {
  if (!par) lvl[u] = D[u] = 0;
  P[u][0] = par;
  int pos = -1;
  for (int v : g[u]) {
    int w = wt[u][++pos];
    if (v == par) continue;
    lvl[v] = 1 + lvl[u];
    D[v] = w + D[u];
    predfs(v, u);
  }
}
void prelca(int n) {
  int i, j;
  for (i = 0; i < LG; i++)
    for (j = 0; j < n + 1; j++) P[j][i] = -1;
  lvl[0] = -1;
  predfs(1, 0);
  for (i = 1; i < LG; i++) {
    for (j = 1; j < n + 1; j++)
      if (P[j][i - 1] != -1) P[j][i] = P[P[j][i - 1]][i - 1];
  }
}
int lca(int u, int v) {
  int i, lg;
  if (lvl[u] < lvl[v]) swap(u, v);
  for (lg = 0; (1 << lg) <= lvl[u]; lg++)
    ;
  lg--;
  for (i = lg; i >= 0; i--) {
    if (lvl[u] - (1 << i) >= lvl[v]) u = P[u][i];
  }
  if (u == v) return u;
  for (i = lg; i >= 0; i--) {
    if (P[u][i] != -1 and P[u][i] != P[v][i]) u = P[u][i], v = P[v][i];
  }
  return P[u][0];
}
long long dis(int u, int v) {
  if (u == v) return 0;
  if (lvl[u] < lvl[v]) swap(u, v);
  int w = lca(u, v);
  return D[u] + D[v] - 2 * D[w];
}
int tot = 0;
void dfs2(int u, int par) {
  if (par == 0) tot = 0;
  sz[u] = 1;
  tot++;
  for (int v : g[u]) {
    if (gvis[v] or v == par) continue;
    dfs2(v, u);
    sz[u] += sz[v];
  }
}
int centroid(int u, int par) {
  for (int v : g[u]) {
    if (v == par or gvis[v]) continue;
    if (2 * sz[v] > tot) return centroid(v, u);
  }
  return u;
}
void decompose(int u, int par) {
  dfs2(u, 0);
  int cen = centroid(u, 0);
  gvis[cen] = 1;
  if (par) c_par[cen] = par;
  for (int v : g[cen])
    if (!gvis[v]) decompose(v, cen);
}
void build_centroid_tree(int n) {
  int i;
  for (i = 1; i < n + 1; i++)
    if (c_par[i]) cg[c_par[i]].push_back(i);
}
void calc_root(int u, int root) {
  stree[root].push_back(dis(u, root));
  for (int v : cg[u]) calc_root(v, root);
}
void calc_contri(int u, int root) {
  int par = c_par[root];
  contri[root].push_back(dis(u, par));
  for (int v : cg[u]) calc_contri(v, root);
}
void traverse_centroid_tree(int u, int par) {
  for (int v : cg[u]) {
    if (v == par) continue;
    traverse_centroid_tree(v, u);
  }
  calc_root(u, u);
  if (!par) return;
  calc_contri(u, u);
}
bool f(long long val, long long x) { return val >= x; }
int bin(vector<long long> &a, long long val, int lo, int hi) {
  if (a.empty()) return 0;
  if (val < 0) return 0;
  if (a[0] > val) return 0;
  if (lo == hi) return lo + 1;
  if (lo + 1 == hi) {
    if (f(val, a[hi])) return hi + 1;
    return lo + 1;
  }
  int mid = (lo + hi) / 2;
  if (f(val, a[mid]))
    return bin(a, val, mid, hi);
  else
    return bin(a, val, lo, mid - 1);
}
int query(int v, long long l) {
  int ans = bin(stree[v], l, 0, (int)stree[v].size() - 1);
  int u = v;
  int orig = v;
  v = c_par[v];
  while (v) {
    long long y = dis(orig, v);
    ans += bin(stree[v], l - y, 0, (int)stree[v].size() - 1);
    ans -= bin(contri[u], l - y, 0, (int)contri[u].size() - 1);
    u = v;
    v = c_par[v];
  }
  return ans;
}
long long ans[N];
void update(int u) {
  int cur = u;
  while (cur) {
    ans[cur] = min(ans[cur], dis(cur, u));
    cur = c_par[cur];
  }
}
int query(int u) {
  long long res = mod;
  int cur = u;
  while (cur) {
    res = min(res, dis(cur, u) + ans[cur]);
    cur = c_par[cur];
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long i, n, k, j, u, v, w, q;
  int t;
  cin >> n >> q;
  for (i = 0; i < n + 1; i++) ans[i] = mod;
  for (i = 0; i < n - 1; i++) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
    wt[v].push_back(1);
    wt[u].push_back(1);
  }
  prelca(n);
  decompose(1, 0);
  build_centroid_tree(n);
  update(1);
  while (q--) {
    cin >> v >> w;
    if (v == 1) {
      update(w);
    } else {
      cout << query(w) << endl;
    }
  }
  return 0;
}
