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;
void showa(long long int a[], long long int n) {
  for (long long int i = 1; i <= n; i++) cout << a[i] << ' ';
  cout << "\n";
}
void showv(vector<long long int> v) {
  for (long long int i = 0; i < v.size(); i++) cout << v[i] << ' ';
  cout << "\n";
}
vector<long long int> vec[100005];
long long int timer, l, n;
long long int tin[100005], tout[100005], depth[100005], dist[100005];
long long int up[100005][70];
void dfs2(long long int u, long long int p) {
  tin[u] = ++timer;
  up[u][0] = p;
  for (long long int i = 1; i <= l; ++i) {
    if (up[u][i - 1] < 0)
      up[u][i] = up[0][i - 1];
    else
      up[u][i] = up[up[u][i - 1]][i - 1];
  }
  for (long long int j : vec[u]) {
    if (j != p) {
      depth[j] = depth[u] + 1;
      dfs2(j, u);
    }
  }
  tout[u] = ++timer;
}
bool is_ancestor(long long int u, long long int v) {
  if (u < 0) u = 0;
  if (v < 0) v = 0;
  return tin[u] <= tin[v] && tout[u] >= tout[v];
}
long long int lca(long long int u, long long int v) {
  if (is_ancestor(u, v)) return u;
  if (is_ancestor(v, u)) return v;
  for (long long int i = l; i >= 0; --i) {
    if (!is_ancestor(up[u][i], v)) u = up[u][i];
  }
  return up[u][0];
}
long long int first(long long int u, long long int v) {
  return depth[u] + depth[v] - (2 * depth[lca(u, v)]);
}
struct CentroidDecomposition {
  vector<set<int>> tree;
  vector<int> dad;
  vector<int> sub;
  CentroidDecomposition(vector<set<int>> &tree) : tree(tree) {
    int n = tree.size();
    dad.resize(n);
    sub.resize(n);
    build(0, -1);
  }
  void build(int u, int p) {
    int n = dfs(u, p);
    int centroid = dfs(u, p, n);
    if (p == -1) p = centroid;
    dad[centroid] = p + 1;
    vector<int> to;
    for (auto v : tree[centroid]) to.push_back(v);
    for (int i = 0; i < to.size(); i++) {
      tree[centroid].erase(to[i]), tree[to[i]].erase(centroid),
          build(to[i], centroid);
    }
  }
  int dfs(int u, int p) {
    sub[u] = 1;
    for (auto v : tree[u])
      if (v != p) sub[u] += dfs(v, u);
    return sub[u];
  }
  int dfs(int u, int p, int n) {
    for (auto v : tree[u])
      if (v != p and sub[v] > n / 2) return dfs(v, u, n);
    return u;
  }
  int operator[](int i) { return dad[i]; }
};
void solve() {
  long long int i, q, u, v;
  cin >> n >> q;
  l = ceil(log2(n));
  timer = 0;
  for (i = 1; i < n; i++) {
    cin >> u >> v;
    u--;
    v--;
    vec[u].push_back(v);
    vec[v].push_back(u);
  }
  vector<set<int>> tr;
  tr.resize(n);
  for (i = 0; i < n; i++) {
    for (int j = 0; j < vec[i].size(); j++) {
      tr[i].insert(vec[i][j]);
      tr[vec[i][j]].insert(i);
    }
  }
  CentroidDecomposition cd(tr);
  dfs2(0, -1);
  for (i = 0; i < n; i++) {
    dist[i] = INT_MAX;
    cd.dad[i]--;
  }
  v = 0;
  u = 0;
  while (1) {
    dist[u] = min(dist[u], first(u, v));
    if (u == cd.dad[u]) break;
    u = cd.dad[u];
  }
  for (i = 1; i <= q; i++) {
    long long int t, v;
    cin >> t >> v;
    v--;
    if (t == 1) {
      long long int u = v;
      while (1) {
        dist[u] = min(dist[u], first(u, v));
        if (u == cd.dad[u]) break;
        u = cd.dad[u];
      }
    }
    if (t == 2) {
      long long int ans = INT_MAX;
      long long int u = v;
      while (1) {
        ans = min(ans, first(u, v) + dist[u]);
        if (u == cd.dad[u]) break;
        u = cd.dad[u];
      }
      cout << ans << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  for (long long int test = 1; test <= t; test++) {
    solve();
  }
  return 0;
}
