#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
const int N = 100005, SZ = (1 << 9), LG = 19, MOD = 1e6;
int n, m, cl[N], dist[N], dep[N], fst[N], st[LG][2 * N], lg[2 * N];
vector<int> ord, g[N];
void bfs() {
  queue<int> q;
  for (int i = 1; i <= n; ++i) {
    if (cl[i] == 1) {
      dist[i] = 0;
      q.push(i);
    } else {
      dist[i] = (int)2e9;
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : g[u]) {
      if (dist[v] > dist[u] + 1) {
        dist[v] = dist[u] + 1;
        q.push(v);
      }
    }
  }
}
void dfs(int u, int p = -1) {
  ord.push_back(u);
  if (fst[u] == -1) fst[u] = (int)ord.size() - 1;
  for (auto v : g[u]) {
    if (v != p) {
      dep[v] = dep[u] + 1;
      dfs(v, u);
      ord.push_back(u);
    }
  }
}
void init() {
  dfs(1);
  int sz = 2 * n - 1;
  st[0][0] = ord[0];
  for (int i = 2; i <= sz; ++i) {
    lg[i] = lg[i >> 1] + 1;
    st[0][i - 1] = ord[i - 1];
  }
  for (int j = 1; j < LG; ++j) {
    for (int i = 0; i + (1 << j) - 1 < sz; ++i) {
      st[j][i] = st[j - 1][i];
      if (dep[st[j - 1][i + (1 << (j - 1))]] < dep[st[j - 1][i]]) {
        st[j][i] = st[j - 1][i + (1 << (j - 1))];
      }
    }
  }
}
int lca(int u, int v) {
  int l = fst[u], r = fst[v];
  if (r < l) swap(l, r);
  int le = lg[r - l + 1];
  int ans = st[le][l];
  if (dep[st[le][r - (1 << le) + 1]] < dep[st[le][l]]) {
    ans = st[le][r - (1 << le) + 1];
  }
  return ans;
}
int dst(int u, int v) { return dep[u] + dep[v] - 2 * dep[lca(u, v)]; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0, u, v; i < n - 1; ++i) {
    cin >> u >> v;
    g[u].push_back(v), g[v].push_back(u);
  }
  cl[1] = 1;
  fill(fst, fst + N, -1);
  init();
  bfs();
  int sc = SZ;
  vector<int> vtc;
  for (int i = 0, t, v; i < m; ++i) {
    if (sc-- == 0) {
      bfs();
      vtc.clear();
      sc = SZ;
    }
    cin >> t >> v;
    if (t == 1) {
      cl[v] = 1;
      vtc.push_back(v);
    } else {
      int ans = dist[v];
      for (auto x : vtc) {
        ans = min(ans, dst(v, x));
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
