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 N = int(1e5) + 10;
const int LOGN = 20;
int INF = int(1e9);
set<int> graph[N];
int parent[N];
int subSize[N];
int level[N];
int minDist[N];
int dp[LOGN][N];
int n, m;
int nn;
void findLevelAndParent(int c) {
  set<int>::iterator it;
  for (it = graph[c].begin(); it != graph[c].end(); it++) {
    if (*it != dp[0][c]) {
      dp[0][*it] = c;
      level[*it] = level[c] + 1;
      findLevelAndParent(*it);
    }
  }
}
void precomputation() {
  for (int i = 0; i < n; i++) {
    minDist[i] = INF;
  }
  level[0] = 0;
  dp[0][0] = 0;
  findLevelAndParent(0);
  for (int i = 1; i < LOGN; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] = dp[i - 1][dp[i - 1][j]];
    }
  }
}
int findLCA(int a, int b) {
  if (level[a] > level[b]) {
    swap(a, b);
  }
  int d = level[b] - level[a];
  for (int i = 0; i < LOGN; i++) {
    if (d & (1 << i)) {
      b = dp[i][b];
    }
  }
  if (a == b) {
    return a;
  }
  for (int i = LOGN - 1; i >= 0; i--) {
    int par1 = dp[i][a];
    int par2 = dp[i][b];
    if (par1 != par2) {
      a = par1;
      b = par2;
    }
  }
  return dp[0][a];
}
int dist(int a, int b) {
  return level[a] + level[b] - 2 * level[findLCA(a, b)];
}
void subtreeSize(int c, int prev) {
  subSize[c] = 1;
  nn++;
  set<int>::iterator it;
  for (it = graph[c].begin(); it != graph[c].end(); it++) {
    if (*it != prev) {
      subtreeSize(*it, c);
      subSize[c] += subSize[*it];
    }
  }
}
int findCentroid(int c, int prev) {
  set<int>::iterator it;
  for (it = graph[c].begin(); it != graph[c].end(); it++) {
    if (*it != prev && subSize[*it] > nn / 2) {
      return findCentroid(*it, c);
    }
  }
  return c;
}
void decomposeTree(int root, int prev) {
  nn = 0;
  subtreeSize(root, root);
  int centroid = findCentroid(root, root);
  if (prev == -1) {
    prev = centroid;
  }
  parent[centroid] = prev;
  set<int>::iterator it;
  for (it = graph[centroid].begin(); it != graph[centroid].end(); it++) {
    graph[*it].erase(centroid);
    decomposeTree(*it, centroid);
  }
  graph[centroid].clear();
}
void mark(int c) {
  int x = c;
  for (;;) {
    minDist[x] = min(minDist[x], dist(x, c));
    if (x == parent[x]) {
      break;
    }
    x = parent[x];
  }
}
int findFestiveCity(int c) {
  int x = c;
  int ret = INF;
  for (;;) {
    ret = min(ret, dist(c, x) + minDist[x]);
    if (x == parent[x]) {
      break;
    }
    x = parent[x];
  }
  return ret;
}
void input() {
  int a, b;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d %d", &a, &b);
    graph[a - 1].insert(b - 1);
    graph[b - 1].insert(a - 1);
  }
}
int main() {
  input();
  precomputation();
  decomposeTree(0, -1);
  mark(0);
  int q, c;
  while (m--) {
    scanf("%d %d", &q, &c);
    c--;
    if (q == 1) {
      mark(c);
    } else {
      int result = findFestiveCity(c);
      printf("%d\n", result);
    }
  }
  return 0;
}
