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> vec[150000];
int block = 400;
int depth[150000];
int par[20][150000];
void traverse(int pos, int prev, int h) {
  par[0][pos] = prev;
  depth[pos] = h;
  int sz = vec[pos].size();
  for (int i = 0; i < sz; i++) {
    int nx = vec[pos][i];
    if (nx == prev) continue;
    traverse(nx, pos, h + 1);
  }
  return;
}
void build() {
  for (int i = 1; i < 20; i++) {
    for (int j = 1; j <= 100000; j++) {
      par[i][j] = par[i - 1][par[i - 1][j]];
    }
  }
}
vector<int> temp;
int dist[150000];
int LCA(int x, int y) {
  if (depth[x] < depth[y]) swap(x, y);
  int diff = depth[x] - depth[y];
  for (int i = 19; i >= 0; i--) {
    if ((diff & (1 << i))) {
      diff -= (1 << i);
      x = par[i][x];
    }
  }
  if (x == y) return x;
  for (int i = 19; i >= 0; i--) {
    if (depth[x] >= (1 << i) && par[i][x] != par[i][y]) {
      x = par[i][x];
      y = par[i][y];
    }
  }
  return par[0][x];
}
int path(int x, int y) {
  int v = LCA(x, y);
  return (depth[x] - depth[v]) + (depth[y] - depth[v]);
}
void bfs() {
  queue<int> q;
  int sz = temp.size();
  for (int i = 0; i < sz; i++) {
    int nx = temp[i];
    dist[nx] = 0;
    q.push(nx);
  }
  temp.clear();
  while (!q.empty()) {
    int pos = q.front();
    q.pop();
    int sz = vec[pos].size();
    for (int i = 0; i < sz; i++) {
      int nx = vec[pos][i];
      if (dist[nx] > dist[pos] + 1) {
        dist[nx] = dist[pos] + 1;
        q.push(nx);
      }
    }
  }
}
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  for (int i = 1; i < n; i++) {
    int t, f;
    scanf("%d %d", &t, &f);
    vec[f].push_back(t);
    vec[t].push_back(f);
  }
  for (int i = 1; i <= n; i++) dist[i] = 1e9;
  dist[1] = 0;
  temp.push_back(1);
  traverse(1, 0, 1);
  build();
  for (int i = 0; i < q; i++) {
    int type, v;
    scanf("%d %d", &type, &v);
    if (type == 1)
      temp.push_back(v);
    else {
      int ans = dist[v];
      int sz = temp.size();
      for (int j = 0; j < sz; j++) {
        ans = min(ans, path(v, temp[j]));
      }
      printf("%d\n", ans);
    }
    if (i % block == 0) bfs();
  }
  return 0;
}
