#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 2;
const int LOG = 17;
const int inf = 1e9;
int jump[LOG][maxn];
int depth[maxn];
bool red[maxn];
int tin[maxn];
int tout[maxn];
int tmr = 0;
int dist[maxn];
int nearest[maxn];
vector<int> e[maxn];
vector<int> New;
void dfs(int v, int id, int p, int h) {
  if (id == 0)
    jump[id][v] = p;
  else
    jump[id][v] = jump[id - 1][jump[id - 1][v]];
  depth[v] = h;
  for (int i = 0; i < (int)e[v].size(); i++)
    if (e[v][i] != p) dfs(e[v][i], id, v, h + 1);
}
void dfsT(int v, int p) {
  tin[v] = tmr++;
  for (int i = 0; i < (int)e[v].size(); i++)
    if (e[v][i] != p) dfsT(e[v][i], v);
  tout[v] = tmr++;
}
int dfs1(int v, int p) {
  int res = inf;
  if (red[v]) res = 0;
  for (int i = 0; i < (int)e[v].size(); i++)
    if (e[v][i] != p) res = min(res, dfs1(e[v][i], v) + 1);
  return nearest[v] = res;
}
void dfs2(int v, int p, int d) {
  d = min(d, nearest[v]);
  dist[v] = d;
  for (int i = 0; i < (int)e[v].size(); i++)
    if (e[v][i] != p) dfs2(e[v][i], v, d + 1);
}
inline bool pred(int v, int u) {
  return tin[v] <= tin[u] && tout[u] <= tout[v];
}
inline int lca(int v, int u) {
  if (pred(v, u)) return v;
  if (pred(u, v)) return u;
  for (int i = LOG - 1; i >= 0; i--)
    if (!pred(jump[i][v], u)) v = jump[i][v];
  return jump[0][v];
}
inline int len(int v, int u) {
  int z = lca(v, u);
  return (depth[v] - depth[z]) + (depth[u] - depth[z]);
}
void re_build() {
  for (int i = 0; i < (int)New.size(); i++) red[New[i]] = 1;
  New.clear();
  dfs1(0, -1);
  dfs2(0, -1, inf);
}
int main() {
  int n, m, m_sqrt, v, u, ans, t;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d", &v, &u);
    v--;
    u--;
    e[v].push_back(u);
    e[u].push_back(v);
  }
  for (int i = 0; i < LOG; i++) dfs(0, i, 0, 0);
  dfsT(0, -1);
  m_sqrt = sqrt(m * log(n));
  if (m_sqrt == 0) m_sqrt++;
  red[0] = 1;
  re_build();
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &t, &v);
    v--;
    if (t == 1) {
      New.push_back(v);
      if ((int)New.size() == m_sqrt) re_build();
    }
    if (t == 2) {
      ans = dist[v];
      for (int j = 0; j < (int)New.size(); j++) ans = min(ans, len(v, New[j]));
      printf("%d\n", ans);
    }
  }
  return 0;
}
