#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2, block = 800;
const int logN = 17;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
int n, m, ers[N], f[N][logN], depth[N], ans[N], child[N], par[N];
vector<int> g[N];
void dfs(int u, int p = 0) {
  f[u][0] = p;
  depth[u] = depth[p] + 1;
  for (int i = 1; i < logN; i++) f[u][i] = f[f[u][i - 1]][i - 1];
  for (int v : g[u]) {
    if (v == p) continue;
    dfs(v, u);
  }
}
int dfs2(int u, int p = 0) {
  child[u] = 1;
  for (int v : g[u]) {
    if (!ers[v] && v != p) {
      dfs2(v, u);
      child[u] += child[v];
    }
  }
  return child[u];
}
int get_centroid(int u, int sz, int p = 0) {
  for (int v : g[u]) {
    if (!ers[v] && v != p && child[v] * 2 > sz) return get_centroid(v, sz, u);
  }
  return u;
}
void centroid(int u = 1, int p = 0) {
  int cen = get_centroid(u, dfs2(u));
  ers[cen] = true;
  par[cen] = p;
  for (int v : g[cen])
    if (!ers[v]) centroid(v, cen);
}
int lca(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  for (int i = logN - 1; i >= 0; i--) {
    if (depth[f[u][i]] >= depth[v]) u = f[u][i];
  }
  if (u == v) return u;
  for (int i = logN - 1; i >= 0; i--) {
    if (f[u][i] != f[v][i]) {
      u = f[u][i];
      v = f[v][i];
    }
  }
  return f[u][0];
}
int dist(int u, int v) { return depth[u] + depth[v] - 2 * depth[lca(u, v)]; }
void update(int u) {
  ans[u] = 0;
  for (int p = par[u]; p; p = par[p]) ans[p] = min(ans[p], dist(u, p));
}
void query(int u) {
  for (int p = par[u]; p; p = par[p]) ans[u] = min(ans[u], ans[p] + dist(u, p));
  cout << ans[u] << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1);
  centroid();
  for (int i = 1; i <= n; i++) ans[i] = INF;
  update(1);
  while (m--) {
    int type, u;
    cin >> type >> u;
    if (type == 1)
      update(u);
    else
      query(u);
  }
  return 0;
}
