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 N = 1e5 + 7;
const int INF = 1e9 + 7;
int n, m, lg[N << 1], mind[N];
vector<int> e[N], E[N];
bool vis[N];
int tot, dep[N], L[N], st[N << 1][20];
inline int rmin(int x, int y) { return dep[x] < dep[y] ? x : y; }
void dfs(int u, int p) {
  L[u] = tot, st[tot++][0] = u;
  for (int i = (0); i < (((int)(e[u]).size())); ++i) {
    int v = e[u][i];
    if (v == p) continue;
    dep[v] = dep[u] + 1;
    dfs(v, u);
    st[tot++][0] = u;
  }
}
void lca_init() {
  lg[1] = 0;
  for (int i = (2); i < (N << 1); ++i) lg[i] = lg[i >> 1] + 1;
  tot = 0, dfs(1, -1);
  for (int j = (1); j < (20); ++j) {
    int lim = tot + 1 - (1 << j);
    for (int i = (0); i < (lim); ++i)
      st[i][j] = rmin(st[i][j - 1], st[i + (1 << j >> 1)][j - 1]);
  }
}
int lca(int x, int y) {
  x = L[x], y = L[y];
  if (x > y) swap(x, y);
  int k = lg[y - x + 1];
  return rmin(st[x][k], st[y - (1 << k) + 1][k]);
}
int dis(int x, int y) { return dep[x] + dep[y] - 2 * dep[lca(x, y)]; }
int q[N], f[N], msz[N], size[N];
int find(int _u) {
  int t = 1, u = _u;
  q[0] = u, f[u] = -1;
  for (int h = (0); h < (t); ++h) {
    u = q[h];
    msz[u] = 0, size[u] = 1;
    for (int i = (0); i < (((int)(e[u]).size())); ++i) {
      int v = e[u][i];
      if (vis[v] || v == f[u]) continue;
      f[v] = u, q[t++] = v;
    }
  }
  for (int h = t - 1; h >= 0; --h) {
    u = q[h];
    msz[u] = max(msz[u], t - size[u]);
    if (msz[u] * 2 <= t) return u;
    if (~f[u]) {
      size[f[u]] += size[u];
      msz[f[u]] = max(msz[f[u]], size[u]);
    }
  }
  return 0;
}
void solve(int u, int p) {
  u = find(u);
  f[u] = p, vis[u] = true, mind[u] = INF;
  for (int i = (0); i < (((int)(e[u]).size())); ++i) {
    int v = e[u][i];
    if (vis[v]) continue;
    solve(v, u);
  }
}
void upd(int u) {
  int p = u;
  while (~p) {
    mind[p] = min(mind[p], dis(u, p));
    p = f[p];
  }
}
int qry(int u) {
  int p = u, ret = INF;
  while (~p) {
    ret = min(ret, mind[p] + dis(u, p));
    p = f[p];
  }
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i < (n); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  lca_init();
  solve(1, -1);
  upd(1);
  for (int _m = (0); _m < (m); ++_m) {
    int t, v;
    scanf("%d%d", &t, &v);
    if (t == 1) {
      upd(v);
    } else {
      printf("%d\n", qry(v));
    }
  }
  return 0;
}
