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 NMAX = 100000 + 5;
const int INF = 1000000000;
const int BS = 1000000000 + 7;
const long long INFLL = 1000000000ll * 1000000000ll;
const long double eps = 1e-6;
vector<int> e[NMAX];
int cd_root = -1;
int cd_parent[NMAX];
int cd_depth[NMAX];
vector<int> cd_children[NMAX];
bool cd_added[NMAX];
int sizes[NMAX];
int dfs_cd(int u, int p = -1) {
  int sz = 1;
  for (auto v : e[u]) {
    if (cd_added[v]) continue;
    if (v == p) continue;
    sz += dfs_cd(v, u);
  }
  sizes[u] = sz;
  return sz;
}
void build_cd(int u = 1, int cd_p = -1) {
  dfs_cd(u);
  int bad_size = sizes[u] / 2;
  int p = -1;
  while (true) {
    int mx_v = -1;
    for (auto v : e[u]) {
      if (v == p) continue;
      if (cd_added[v]) continue;
      if (sizes[v] > bad_size) {
        mx_v = v;
      }
    }
    if (mx_v == -1) {
      break;
    }
    p = u;
    u = mx_v;
  }
  if (cd_p == -1) {
    cd_root = u;
  }
  cd_parent[u] = cd_p;
  cd_depth[u] = 1;
  if (cd_p != -1) {
    cd_depth[u] += cd_depth[cd_p];
    cd_children[cd_p].push_back(u);
  }
  cd_added[u] = true;
  for (auto v : e[u]) {
    if (cd_added[v]) continue;
    build_cd(v, u);
  }
}
map<int, int> cd_dist[NMAX];
bool dist_calculated[NMAX];
void dfs_dist(int u, int centroid_to_add, int cur_dist, int p = -1) {
  cd_dist[centroid_to_add][u] = cur_dist;
  for (auto v : e[u]) {
    if (v == p) continue;
    if (v == centroid_to_add) continue;
    if (dist_calculated[v]) continue;
    dfs_dist(v, centroid_to_add, cur_dist + 1, u);
  }
}
void build_dist(int u) {
  dfs_dist(u, u, 0);
  dist_calculated[u] = true;
  for (auto v : cd_children[u]) {
    build_dist(v);
  }
}
int dist(int u, int v) {
  int lu = u;
  int lv = v;
  while (cd_depth[lu] != cd_depth[lv]) {
    if (cd_depth[lu] > cd_depth[lv]) {
      swap(lu, lv);
    }
    lv = cd_parent[lv];
  }
  while (lu != lv) {
    lu = cd_parent[lu];
    lv = cd_parent[lv];
  }
  int lca = lv;
  return cd_dist[lca][u] + cd_dist[lca][v];
}
int t[NMAX];
void modify(int v) {
  int cur_centroid = v;
  while (cur_centroid != -1) {
    t[cur_centroid] = min(t[cur_centroid], dist(cur_centroid, v));
    cur_centroid = cd_parent[cur_centroid];
  }
}
int query(int v) {
  int best = INF;
  int cur_centroid = v;
  while (cur_centroid != -1) {
    best = min(best, dist(cur_centroid, v) + t[cur_centroid]);
    cur_centroid = cd_parent[cur_centroid];
  }
  return best;
}
int main(int argc, char** argv) {
  if (argc > 1 && strcmp(argv[1], "seland") == 0) {
    freopen(
        "/Users/seland/Workspace/Contests/Olymp/XcodeTemplate/SolutionTemplate/"
        "SolutionTemplate/input.txt",
        "r", stdin);
    freopen(
        "/Users/seland/Workspace/Contests/Olymp/XcodeTemplate/SolutionTemplate/"
        "SolutionTemplate/output.txt",
        "w", stdout);
  }
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    t[i] = INF;
  }
  build_cd();
  build_dist(cd_root);
  modify(1);
  for (int j = 0; j < m; j++) {
    int tp, v;
    cin >> tp >> v;
    if (tp == 1) {
      modify(v);
    } else {
      cout << query(v) << endl;
    }
  }
  return 0;
}
