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;
using namespace std;
pair<int, int> operator+(const pair<int, int>& p1, const pair<int, int>& p2) {
  return pair<int, int>(p1.first + p2.first, p1.second + p2.second);
}
pair<int, int> operator-(const pair<int, int>& p1, const pair<int, int>& p2) {
  return pair<int, int>(p1.first - p2.first, p1.second - p2.second);
}
int operator*(const pair<int, int>& p1, const pair<int, int>& p2) {
  return (p1.first * p2.first + p1.second * p2.second);
}
int operator^(const pair<int, int>& p1, const pair<int, int>& p2) {
  return (p1.first * p2.second - p1.second * p2.first);
}
int n, m;
vector<int> g[100005];
int de[100005];
bool del[100005];
int fa[100005][21];
int ssize[100005];
int cd_fa[100005];
int ans[100005];
void dfs(int x, int pa, int dep) {
  fa[x][0] = pa;
  de[x] = dep;
  for (int v : g[x]) {
    if (v != pa) {
      dfs(v, x, dep + 1);
    }
  }
}
void lca_init() {
  for (int j = 1; j < 21; ++j) {
    for (int i = 1; i <= n; ++i) {
      if (fa[i][j - 1] == -1)
        fa[i][j] == -1;
      else
        fa[i][j] = fa[fa[i][j - 1]][j - 1];
    }
  }
}
int get_lca(int x, int y) {
  if (de[x] < de[y]) swap(x, y);
  for (int i = 0; i < 21; ++i) {
    if ((de[x] - de[y]) >> i & 1) {
      x = fa[x][i];
    }
  }
  if (x == y) return x;
  for (int i = 20; i >= 0; --i) {
    if (fa[x][i] != fa[y][i]) {
      x = fa[x][i];
      y = fa[y][i];
    }
  }
  return fa[x][0];
}
int get_dist(int x, int y) {
  int lca = get_lca(x, y);
  return de[x] + de[y] - (2 * de[lca]);
}
void get_size(int x, int pa) {
  ssize[x] = 1;
  for (int v : g[x]) {
    if (!del[v] && v != pa) {
      get_size(v, x);
      ssize[x] += ssize[v];
    }
  }
}
int get_cen(int x, int pa, int n) {
  for (int v : g[x]) {
    if (!del[v] && v != pa && ssize[v] > n / 2) {
      return get_cen(v, x, n);
    }
  }
  return x;
}
void c_d(int x, int pa) {
  get_size(x, pa);
  int cen = get_cen(x, pa, ssize[x]);
  cd_fa[cen] = pa;
  del[cen] = 1;
  for (int v : g[cen]) {
    if (!del[v] && v != pa) {
      c_d(v, cen);
    }
  }
}
void paint(int x) {
  int y = x;
  while (y != -1) {
    ans[y] = min(ans[y], get_dist(x, y));
    y = cd_fa[y];
  }
}
int query(int x) {
  int y = x;
  int minn = INT_MAX;
  while (y != -1) {
    minn = min(minn, ans[y] + get_dist(x, y));
    y = cd_fa[y];
  }
  return minn;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 1; i <= n; ++i) {
    ans[i] = 1e9;
  }
  dfs(1, -1, 0);
  lca_init();
  c_d(1, -1);
  paint(1);
  for (int i = 0; i < m; ++i) {
    int t, v;
    cin >> t >> v;
    if (t == 1)
      paint(v);
    else
      cout << query(v) << "\n";
  }
  return 0;
}
