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> v[200005], tour, w;
queue<int> qo;
vector<pair<int, int> > queries;
int n, h[200005], first[200005], stmin[200005][20];
int vis1[200005], vis2[200005], ans[200005] = {0};
void height_initialise(int x, int y) {
  h[x] = y;
  vis1[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    int node = v[x][i];
    if (vis1[node] == 0) {
      height_initialise(node, y + 1);
    }
  }
}
void euler(int x, int y) {
  vis2[x] = 1;
  tour.push_back(x);
  for (int i = 0; i < v[x].size(); i++) {
    int node = v[x][i];
    if (vis2[node] == 0) {
      euler(node, x);
    }
  }
  if (y != 0) tour.push_back(y);
}
void euler_tour() {
  euler(1, 0);
  for (int i = 0; i < tour.size(); i++) {
    if (first[tour[i]] == 0) {
      first[tour[i]] = i;
    }
  }
}
void sparsemin() {
  int i, j, x, y;
  for (i = 0; i < tour.size(); i++) {
    stmin[i][0] = tour[i];
  }
  for (j = 1; (1 << j) <= tour.size(); j++) {
    for (i = 0; i <= tour.size() - (1 << j); i++) {
      x = stmin[i][j - 1];
      y = stmin[i + (1 << (j - 1))][j - 1];
      if (h[x] > h[y]) {
        stmin[i][j] = y;
      } else {
        stmin[i][j] = x;
      }
    }
  }
}
int spminquery(int l, int r) {
  int length, k, x, y;
  length = r - l + 1;
  k = log2(length);
  x = stmin[l][k];
  y = stmin[l + length - (1 << k)][k];
  if (h[x] < h[y]) {
    return x;
  }
  return y;
}
int func() {
  int x, node, i;
  queue<int> qo;
  for (i = 0; i < w.size(); i++) {
    ans[w[i]] = 0;
    qo.push(w[i]);
  }
  while (qo.size()) {
    x = qo.front();
    qo.pop();
    for (i = 0; i < v[x].size(); i++) {
      node = v[x][i];
      if (ans[x] + 1 < ans[node]) {
        ans[node] = ans[x] + 1;
        qo.push(node);
      }
    }
  }
  w.clear();
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int i, x, y, z, l, r, q, m;
  cin >> n >> m;
  for (i = 0; i < n - 1; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (i = 0; i <= n; i++) {
    ans[i] = 1e9;
  }
  height_initialise(1, 0);
  euler_tour();
  sparsemin();
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    queries.push_back(make_pair(x, y));
  }
  int bs, bl, node1, node2, X, Y, Z, j, sum;
  w.push_back(1);
  bs = sqrt(m);
  func();
  for (i = 0; i < m; i++) {
    int p = queries[i].first;
    int node1 = queries[i].second;
    if (p == 2) {
      int temp = ans[node1];
      for (j = 0; j < w.size(); j++) {
        node2 = w[j];
        X = first[node1];
        Y = first[node2];
        Z = spminquery(min(X, Y), max(X, Y));
        sum = h[node1] + h[node2] - 2 * h[Z];
        temp = min(temp, sum);
      }
      cout << temp << "\n";
    } else {
      w.push_back(node1);
    }
    if (i % bs == 0 && i != 0) {
      func();
    }
  }
  return 0;
}
