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 maxn = 2e5 + 10;
const int base = 31337;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;
const int block = 300;
int n, m;
vector<int> graph[maxn];
int ds[maxn];
int dp[logo + 10][maxn];
int dis[maxn];
vector<int> v;
queue<int> q;
void dfs(int x, int parr, int d) {
  dp[0][x] = parr;
  ds[x] = d;
  for (int i = 0; i < graph[x].size(); i++) {
    int tren = graph[x][i];
    if (tren != parr) dfs(tren, x, d + 1);
  }
}
int lif(int x, int val) {
  for (int i = 0; i <= logo; i++) {
    if (val & (1 << i)) x = dp[i][x];
  }
  return x;
}
int lca(int x, int y) {
  if (ds[x] > ds[y])
    x = lif(x, ds[x] - ds[y]);
  else
    y = lif(y, ds[y] - ds[x]);
  if (x == y) return x;
  for (int i = logo; i >= 0; i--) {
    if (dp[i][x] != dp[i][y]) x = dp[i][x], y = dp[i][y];
  }
  return dp[0][x];
}
int distance(int x, int y) {
  int a = lca(x, y);
  return ds[x] + ds[y] - ds[a] - ds[a];
}
void update() {
  for (int i = 0; i < v.size(); i++) {
    int tren = v[i];
    dis[tren] = 0;
    q.push(tren);
  }
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < graph[x].size(); i++) {
      int tren = graph[x][i];
      if (dis[tren] > 1 + dis[x]) {
        dis[tren] = 1 + dis[x];
        q.push(tren);
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  dfs(1, 0, 0);
  for (int i = 1; i <= logo; i++)
    for (int j = 1; j <= n; j++) dp[i][j] = dp[i - 1][dp[i - 1][j]];
  v.push_back(1);
  memset(dis, inf, sizeof dis);
  for (int i = 0; i < m; i++) {
    if (i % block == 0) {
      update();
      v.clear();
    }
    int type, x;
    scanf("%d%d", &type, &x);
    if (type == 1) {
      v.push_back(x);
    } else {
      int dist = dis[x];
      for (int i = 0; i < v.size(); i++) {
        int tren = v[i];
        dist = min(dist, distance(x, tren));
      }
      printf("%d\n", dist);
    }
  }
  return 0;
}
