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;
const double PI = acos(-1);
template <typename T>
T getint() {
  T val = 0;
  char c;
  while ((c = getchar()) && !(c >= '0' && c <= '9'))
    ;
  do {
    val = (val * 10) + c - '0';
  } while ((c = getchar()) && (c >= '0' && c <= '9'));
  return val;
}
const int maxn = 100001, hgt = 17;
int n, m;
vector<int> adj[maxn];
int par[maxn], b[maxn], lvl[maxn];
int dp[maxn][hgt];
void dfs_lca(int x, int p = -1, int lev = 0) {
  b[x] = 1;
  par[x] = p;
  lvl[x] = lev;
  for (auto i : adj[x]) {
    if (!b[i]) {
      dfs_lca(i, x, lev + 1);
    }
  }
  b[x] = 2;
}
void init() {
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; ++i) {
    dp[i][0] = par[i];
  }
  for (int j = 1; j < hgt; ++j) {
    for (int i = 1; i <= n; ++i) {
      if (dp[i][j - 1] != -1) {
        dp[i][j] = dp[dp[i][j - 1]][j - 1];
      }
    }
  }
}
int lca(int p, int q) {
  if (lvl[p] > lvl[q]) swap(p, q);
  for (int i = hgt - 1; i >= 0; i--) {
    if (dp[q][i] != -1 && lvl[p] <= lvl[dp[q][i]]) q = dp[q][i];
  }
  if (p == q) return p;
  for (int i = hgt - 1; i >= 0; i--) {
    if (dp[q][i] != -1 && dp[q][i] != dp[p][i]) {
      p = dp[p][i];
      q = dp[q][i];
    }
  }
  return dp[p][0];
}
int kth(int p, int k) {
  for (int i = 0; i < hgt; ++i) {
    if (k & (1 << i)) {
      p = dp[p][i];
    }
  }
  return p;
}
int dist(int a, int b) {
  int l = lca(a, b);
  return lvl[a] + lvl[b] - 2 * lvl[l];
}
int banned[maxn];
int b0[maxn], sz[maxn];
void dfs0(int x) {
  b0[x] = 1;
  sz[x] = 1;
  for (auto i : adj[x]) {
    if (b0[i] || banned[i]) continue;
    dfs0(i);
    sz[x] += sz[i];
  }
  b0[x] = 2;
}
int dfs1(int x, int p, int nn) {
  int ind = -1;
  for (auto i : adj[x]) {
    if (banned[i] || i == p) continue;
    if (sz[i] > nn / 2) ind = i;
  }
  if (ind != -1) return dfs1(ind, x, nn);
  return x;
}
vector<int> cadj[maxn];
int cpar[maxn];
int decompose(int x = 1) {
  memset(b0, 0, sizeof b0);
  dfs0(x);
  int centroid = dfs1(x, -1, sz[x]);
  banned[centroid] = 1;
  for (auto i : adj[centroid]) {
    if (!banned[i]) {
      int child = decompose(i);
      cadj[centroid].push_back(child);
      cpar[child] = centroid;
    }
  }
  return centroid;
}
int main() {
  n = getint<int>();
  m = getint<int>();
  for (int i = 1; i < n; ++i) {
    int a, b;
    a = getint<int>();
    b = getint<int>();
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs_lca(1);
  init();
  int root = decompose();
  vector<int> ans(n + 1, 1e9);
  for (int i = -1; i < m; ++i) {
    int typ, v;
    if (i >= 0) {
      typ = getint<int>();
      v = getint<int>();
    } else {
      typ = 1;
      v = 1;
    }
    if (typ == 1) {
      int akt = v;
      while (akt) {
        ans[akt] = min(ans[akt], dist(akt, v));
        akt = cpar[akt];
      }
    } else {
      int res = 1e9;
      int akt = v;
      while (akt) {
        res = min(res, ans[akt] + dist(akt, v));
        akt = cpar[akt];
      }
      printf("%d\n", res);
    }
  }
  return 0;
}
