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<long long> tree[200005];
long long sub[200005], num_of_nod, n, m;
bool in_centroid[200005];
long long sprsT[18][200005];
long long level[200005], par[200005];
void dfs(long long s, long long p) {
  for (int i = 0; i < tree[s].size(); i++) {
    if (tree[s][i] != p) {
      par[tree[s][i]] = s;
      level[tree[s][i]] = level[s] + 1;
      dfs(tree[s][i], s);
    }
  }
}
void build_lca(long long u, long long p) {
  for (int i = 0; (1 << i) <= n; i++) {
    for (int j = 1; j <= n; j++) {
      sprsT[i][j] = -1;
    }
  }
  dfs(u, p);
  par[u] = -1;
  for (int j = 1; j <= n; j++) {
    sprsT[0][j] = par[j];
  }
  for (int i = 1; (1 << i) <= n; i++) {
    for (int j = 1; j <= n; j++) {
      long long p = sprsT[i - 1][j];
      if (p != -1) {
        sprsT[i][j] = sprsT[i - 1][p];
      }
    }
  }
}
long long find_lca(long long u, long long v) {
  if (level[u] > level[v]) {
    swap(u, v);
  }
  for (int i = 17; i >= 0; i--) {
    if (sprsT[i][v] != -1 && level[sprsT[i][v]] >= level[u]) {
      v = sprsT[i][v];
    }
  }
  if (u == v) return u;
  for (int i = 17; i >= 0; i--) {
    if (sprsT[i][u] != sprsT[i][v]) {
      v = sprsT[i][v];
      u = sprsT[i][u];
    }
  }
  return par[u];
}
long long dist(long long u, long long v) {
  return level[u] + level[v] - 2 * level[find_lca(u, v)];
}
void centroid_dfs(long long u, long long p) {
  sub[u] = 1;
  num_of_nod++;
  for (int v = 0; v < tree[u].size(); v++)
    if (tree[u][v] != p && !in_centroid[tree[u][v]]) {
      centroid_dfs(tree[u][v], u);
      sub[u] += sub[tree[u][v]];
    }
}
long long find_centroid(long long u, long long p) {
  for (int i = 0; i < tree[u].size(); i++) {
    long long v = tree[u][i];
    if (v != p && !in_centroid[v] && sub[v] > num_of_nod / 2) {
      return find_centroid(v, u);
    }
  }
  return u;
}
vector<long long> centroid_tree[200005];
long long centroid_par[200005];
void centroid_decomposition(long long u, long long p) {
  num_of_nod = 0;
  centroid_dfs(u, u);
  long long centroid = find_centroid(u, u);
  if (p == -1) {
    p = centroid;
  }
  in_centroid[centroid] = true;
  centroid_par[centroid] = p;
  for (int i = 0; i < tree[centroid].size(); i++) {
    if (!in_centroid[tree[centroid][i]]) {
      centroid_decomposition(tree[centroid][i], centroid);
    }
  }
}
long long ans[200005];
void update(long long u) {
  long long x = u;
  while (1) {
    ans[x] = min(ans[x], dist(x, u));
    if (x == centroid_par[x]) break;
    x = centroid_par[x];
  }
}
long long query(long long u) {
  long long x = u;
  long long ret = 1000000000;
  while (1) {
    ret = min(ret, dist(u, x) + ans[x]);
    if (x == centroid_par[x]) break;
    x = centroid_par[x];
  }
  return ret;
}
void init() {
  fill(in_centroid, in_centroid + 200005, false);
  fill(ans, ans + 200005, 1000000000);
}
int main() {
  long long u, v;
  scanf("%lld%lld", &n, &m);
  for (int i = 0; i < n - 1; i++) {
    scanf("%lld%lld", &u, &v);
    tree[u].push_back(v);
    tree[v].push_back(u);
  }
  init();
  level[1] = 0;
  par[1] = 1;
  build_lca(1, 1);
  centroid_decomposition(1, -1);
  update(1);
  long long check, q;
  while (m--) {
    scanf("%lld%lld", &check, &q);
    if (check == 2) {
      printf("%lld\n", query(q));
    } else {
      update(q);
    }
  }
  return 0;
}
