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 INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int MAXN = 100010;
const int LOGN = 18;
int lca[MAXN][LOGN];
int depth[MAXN];
int centroid[MAXN];
int parent[MAXN];
int time_in[MAXN], time_out[MAXN];
int timer = 0;
int subsize[MAXN];
int closest[MAXN];
int n, m;
vector<set<int>> g;
void dfs0(int v, int p) {
  parent[v] = p;
  time_in[v] = timer++;
  for (auto to : g[v]) {
    if (to == p) continue;
    depth[to] = depth[v] + 1;
    dfs0(to, v);
  }
  time_out[v] = timer++;
}
bool is_ancestor(int a, int b) {
  return time_in[a] <= time_in[b] && time_out[a] >= time_out[b];
}
void get_lca() {
  for (int i = 1; i <= n; ++i) lca[i][0] = parent[i];
  for (int d = 1; d < LOGN; ++d) {
    for (int i = 1; i <= n; ++i) {
      lca[i][d] = lca[lca[i][d - 1]][d - 1];
    }
  }
}
int get_ancestor(int a, int b) {
  if (is_ancestor(a, b)) return a;
  if (is_ancestor(b, a)) return b;
  for (int d = LOGN - 1; d > -1; --d)
    if (!is_ancestor(lca[a][d], b)) a = lca[a][d];
  return lca[a][0];
}
int calculate_size(int v, int p = -1) {
  subsize[v] = 1;
  for (auto to : g[v]) {
    if (to == p) continue;
    subsize[v] += calculate_size(to, v);
  }
  return subsize[v];
}
int find_centroid(int size, int v, int p = -1) {
  for (auto to : g[v]) {
    if (to == p) continue;
    if (subsize[to] * 2 > size) return find_centroid(size, to, v);
  }
  return v;
}
void build_centroid(int v, int p = -1) {
  int center = find_centroid(calculate_size(v), v);
  centroid[center] = p;
  for (auto to : g[center]) {
    g[to].erase(center);
    build_centroid(to, center);
  }
  g[center].clear();
}
int dist(int a, int b) {
  return depth[a] + depth[b] - 2 * depth[get_ancestor(a, b)];
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cin >> n >> m;
  g.resize(n + 1);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    g[a].insert(b);
    g[b].insert(a);
  }
  parent[1] = 1;
  depth[1] = 0;
  dfs0(1, 1);
  0;
  get_lca();
  0;
  build_centroid(1);
  0;
  for (int i = 1; i <= n; ++i) closest[i] = depth[i];
  for (int i = 0; i < m; ++i) {
    int t, v;
    cin >> t >> v;
    if (t == 1) {
      closest[v] = 0;
      int c = v;
      while (c != -1) {
        c = centroid[c];
        closest[c] = min(closest[c], dist(c, v));
      }
    } else {
      int ans = closest[v];
      int c = v;
      while (c != -1) {
        c = centroid[c];
        ans = min(ans, closest[c] + dist(c, v));
      }
      cout << ans << endl;
    }
  }
  return 0;
}
