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> neigh[100000];
int RMQ[200000][20];
int T = 0;
int Log2[200001];
int nearest[100000];
bool isMarked[100000];
struct sQuery {
  int v, t;
};
sQuery bucket[320];
int Queue[100000];
int n;
void BFS() {
  int L = 0, R = 0;
  for (int i = 0; i < n; i++) {
    if (isMarked[i]) {
      Queue[R++] = i;
      nearest[i] = 0;
    } else {
      nearest[i] = 1000000000;
    }
  }
  while (L < R) {
    int v = Queue[L++];
    for (int i = 0; i < neigh[v].size(); i++) {
      int u = neigh[v][i];
      if (nearest[u] == 1000000000) {
        nearest[u] = nearest[v] + 1;
        Queue[R++] = u;
      }
    }
  }
}
int depth[100000];
int first[100000];
void DFS(int v, int p, int d) {
  first[v] = T;
  depth[v] = d;
  RMQ[T++][0] = d;
  for (int it = 0; it < neigh[v].size(); ++it) {
    int u = neigh[v][it];
    if (u != p) {
      DFS(u, v, d + 1);
      RMQ[T++][0] = d;
    }
  }
}
void precalcRMQ() {
  for (int j = 0; j < 19; j++) {
    for (int i = 0; i < T; i++) {
      RMQ[i][j + 1] =
          min(RMQ[i][j],
              RMQ[((T - 1) < (i + (1 << j)) ? (T - 1) : (i + (1 << j)))][j]);
    }
  }
}
int LCA(int u, int v) {
  u = first[u];
  v = first[v];
  if (u > v) {
    int t = u;
    u = v;
    v = t;
  }
  int dist = v - u + 1;
  return ((RMQ[u][Log2[dist]]) < (RMQ[v - (1 << Log2[dist]) + 1][Log2[dist]])
              ? (RMQ[u][Log2[dist]])
              : (RMQ[v - (1 << Log2[dist]) + 1][Log2[dist]]));
}
void precalcLog2() {
  Log2[1] = 0;
  int rem = 0;
  for (int i = 2; i < 200001; i++) {
    Log2[i] = Log2[i - 1];
    rem--;
    if (rem < 0) {
      Log2[i]++;
      rem += (1 << Log2[i]);
    }
  }
}
int vertComp[320];
int P;
int main() {
  precalcLog2();
  int m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    neigh[u].push_back(v);
    neigh[v].push_back(u);
  }
  DFS(0, -1, 0);
  precalcRMQ();
  int bucketSize = (int)sqrt(m);
  isMarked[0] = true;
  int i = 0;
  while (i < m) {
    int cnt = 0;
    for (int j = 0; i < m && j < bucketSize; i++, j++, cnt++) {
      scanf("%d %d", &bucket[j].t, &bucket[j].v);
      bucket[j].v--;
    }
    BFS();
    P = 0;
    for (int j = 0; j < cnt; j++) {
      if (bucket[j].t == 2) {
        int ans = nearest[bucket[j].v];
        for (int t = 0; t < P; t++) {
          ans = ((ans) < (depth[bucket[j].v] + depth[vertComp[t]] -
                          2 * LCA(bucket[j].v, vertComp[t]))
                     ? (ans)
                     : (depth[bucket[j].v] + depth[vertComp[t]] -
                        2 * LCA(bucket[j].v, vertComp[t])));
        }
        printf("%d\n", ans);
      } else {
        vertComp[P++] = bucket[j].v;
      }
    }
    for (int j = 0; j < cnt; j++) {
      if (bucket[j].t == 1) {
        isMarked[bucket[j].v] = true;
      }
    }
  }
}
