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;
struct LCA {
  int p;
  LCA() {}
} lca[100001][21];
int n, m;
set<int> AdjList[100001];
int p[100001];
int nChild[100001];
int d[100001];
int f[100001];
int cur_sz;
int lim;
void cal_dist(int u, int par) {
  for (set<int>::iterator it = AdjList[u].begin(); it != AdjList[u].end();
       it++) {
    int v = *it;
    if (v != par) {
      lca[v][0].p = u;
      d[v] = d[u] + 1;
      cal_dist(v, u);
    }
  }
}
void cal_lca() {
  for (int j = 1; j <= 20; j++)
    for (int i = 1; i <= 100000; i++)
      if (lca[i][j - 1].p != -1)
        if (lca[lca[i][j - 1].p][j - 1].p != -1)
          lca[i][j].p = lca[lca[i][j - 1].p][j - 1].p;
}
void cal_Child(int u, int par) {
  cur_sz++;
  nChild[u] = 1;
  for (set<int>::iterator it = AdjList[u].begin(); it != AdjList[u].end();
       it++) {
    int v = *it;
    if (v != par) {
      cal_Child(v, u);
      nChild[u] += nChild[v];
    }
  }
}
int find_Centroid(int u, int par) {
  for (set<int>::iterator it = AdjList[u].begin(); it != AdjList[u].end();
       it++) {
    int v = *it;
    if (v != par && nChild[v] > lim) return find_Centroid(v, u);
  }
  return u;
}
void Decomp(int u, int pre) {
  cur_sz = 0;
  cal_Child(u, -1);
  lim = cur_sz / 2;
  int Centroid = find_Centroid(u, -1);
  p[Centroid] = pre;
  for (set<int>::iterator it = AdjList[Centroid].begin();
       it != AdjList[Centroid].end(); it++) {
    int v = *it;
    AdjList[v].erase(Centroid);
    Decomp(v, Centroid);
  }
}
int find_lca(int u, int v) {
  if (d[u] > d[v]) swap(u, v);
  for (int i = 20; i >= 0; i--)
    if (lca[v][i].p != -1)
      if (d[lca[v][i].p] >= d[u]) v = lca[v][i].p;
  if (u == v) return u;
  for (int i = 20; i >= 0; i--)
    if (lca[v][i].p != -1 && lca[u][i].p != -1)
      if (lca[v][i].p != lca[u][i].p) {
        u = lca[u][i].p;
        v = lca[v][i].p;
      }
  return lca[v][0].p;
}
int dist(int a, int b) { return (d[a] + d[b] - 2 * d[find_lca(a, b)]); }
void update(int u) {
  int z = u;
  while (u) {
    f[u] = min(f[u], dist(z, u));
    u = p[u];
  }
}
int query(int u) {
  int ans = 1e9;
  int z = u;
  while (u) {
    ans = min(ans, f[u] + dist(z, u));
    u = p[u];
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) f[i] = 1e9;
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    cin >> u >> v;
    AdjList[u].insert(v);
    AdjList[v].insert(u);
  }
  d[1] = 0;
  cal_dist(1, 0);
  Decomp(1, 0);
  for (int j = 1; j <= 20; j++)
    for (int i = 1; i <= 100000; i++) lca[i][j].p = -1;
  cal_lca();
  update(1);
  while (m--) {
    int type, u;
    cin >> type >> u;
    if (type == 1)
      update(u);
    else
      cout << query(u) << '\n';
  }
}
