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;
long double pi = acos(-1.0);
long long int power(long long int x, long long int y) {
  long long int temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return (temp * temp);
  else {
    if (y > 0)
      return (((x * temp)) * temp);
    else
      return (temp * temp) / x;
  }
}
long long int mul_inv(long long int n, long long int p, long long int m) {
  if (p == 1) {
    return n % m;
  } else if (p % 2 == 0) {
    long long int t = mul_inv(n, p / 2, m);
    return ((t) * (t)) % m;
  } else {
    long long int t = mul_inv(n, p / 2, m);
    return ((((n % m) * t) % m) * t) % m;
  }
}
bool isprime(long long int n) {
  if (n == 2) {
    return true;
  }
  if (n % 2 == 0) {
    return false;
  }
  for (long long int i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
int n, m;
int already[100007];
int lev[100007];
int p[20][100007];
int a, b;
int vis[100007];
vector<int> tree[100007], current;
void define(int i) {
  vis[i] = 1;
  for (int j = 0; j < tree[i].size(); j++) {
    int k = tree[i][j];
    if (vis[k] == 0) {
      p[0][k] = i;
      lev[k] = lev[i] + 1;
      define(k);
    }
  }
}
int lca(int a, int b) {
  int x = a, y = b;
  for (int i = 17; i >= 0; i--) {
    if (lev[p[i][x]] >= lev[y]) {
      x = p[i][x];
    }
  }
  for (int i = 17; i >= 0; i--) {
    if (lev[p[i][y]] >= lev[x]) {
      y = p[i][y];
    }
  }
  for (int i = 17; i >= 0; i--) {
    if (p[i][x] != p[i][y]) {
      x = p[i][x];
      y = p[i][y];
    }
  }
  if (x != y) {
    x = p[0][x];
    y = p[0][y];
  }
  return x;
}
void bfs() {
  queue<int> q;
  for (int i = 0; i < current.size(); i++) {
    q.push(current[i]);
    already[current[i]] = 0;
  }
  current.clear();
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < tree[u].size(); i++) {
      int v = tree[u][i];
      if (already[u] + 1 < already[v]) {
        already[v] = already[u] + 1;
        q.push(v);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n - 1; i++) {
    cin >> a >> b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) p[0][i] = 0;
  lev[1] = 1;
  define(1);
  for (int i = 1; i <= 17; i++) {
    for (int j = 1; j <= n; j++) {
      p[i][j] = p[i - 1][p[i - 1][j]];
    }
  }
  int square = sqrt(n);
  for (int i = 2; i <= n; i++) {
    already[i] = 1000000007;
  }
  current.push_back(1);
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    if (a == 1) {
      current.push_back(b);
    } else {
      int ans = already[b];
      for (int i = 0; i < current.size(); i++) {
        int k = current[i];
        int lc = lca(k, b);
        ans = min(ans, lev[k] - lev[lc] + lev[b] - lev[lc]);
      }
      cout << ans << endl;
    }
    if (i % square == 0) {
      bfs();
    }
  }
}
