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<int> x[100100];
int d_red[100100];
int lev[100100];
vector<int> temp;
queue<int> q;
int dp[100100][18];
bool vis[100100];
int minn, SQRT = 100;
int n, m;
void bfs_an() {
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    if (vis[node]) continue;
    vis[node] = true;
    for (int i = 0; i < x[node].size(); i++) {
      if (vis[x[node][i]]) continue;
      d_red[x[node][i]] = d_red[node] + 1;
      lev[x[node][i]] = lev[node] + 1;
      dp[x[node][i]][0] = node;
      q.push(x[node][i]);
    }
  }
}
void bfs() {
  for (int i = 0; i < temp.size(); i++) {
    q.push(temp[i]);
  }
  temp.clear();
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    if (!vis[node]) {
      vis[node] = true;
      for (int i = 0; i < x[node].size(); i++) {
        if (!vis[x[node][i]]) {
          d_red[x[node][i]] = min(d_red[x[node][i]], d_red[node] + 1);
          q.push(x[node][i]);
        }
      }
    }
  }
}
int main() {
  for (int i = 2; i <= 1e5; i++) d_red[i] = 1e6;
  cin >> n >> m;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    x[a].push_back(b);
    x[b].push_back(a);
  }
  q.push(1);
  bfs_an();
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= 16; i++) {
    for (int j = 1; j <= n; j++) {
      dp[j][i] = dp[dp[j][i - 1]][i - 1];
    }
  }
  for (int i = 0; i < m; i++) {
    minn = 1e6;
    int a, b;
    cin >> a >> b;
    if (a == 1) {
      temp.push_back(b);
      d_red[b] = 0;
    } else {
      for (int j = 0; j < temp.size(); j++) {
        int l, h;
        l = temp[j];
        h = b;
        if (lev[l] < lev[h]) swap(l, h);
        int L = l, H = h;
        for (int k = 16; k >= 0; k--) {
          if (dp[l][k] != 0) {
            if (lev[dp[l][k]] >= lev[h]) {
              l = dp[l][k];
            }
          }
        }
        if (l == h) {
          minn = min(minn, abs(lev[L] - lev[H]));
          continue;
        }
        for (int k = 16; k >= 0; k--) {
          int A = dp[l][k], B = dp[h][k];
          if (A != B && A != 0 && B != 0) {
            l = A;
            h = B;
          }
        }
        int Lca = dp[l][0];
        minn = min(lev[L] + lev[H] - 2 * lev[Lca], minn);
      }
      cout << min(minn, d_red[b]) << endl;
    }
    if (temp.size() > SQRT) {
      bfs();
      memset(vis, 0, sizeof(vis));
    }
  }
  return 0;
}
