#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const int K = 20;
int F[N][K], level[N], d[N];
long long ans[N];
vector<int> g[N];
void dfs(int x, int y = 0, int lvl = 0) {
  F[x][0] = y;
  for (int i = 1; i < K; i++) F[x][i] = F[F[x][i - 1]][i - 1];
  level[x] = lvl;
  for (auto v : g[x])
    if (v != y) {
      dfs(v, x, lvl + 1);
    }
}
int lca(int x, int y) {
  if (level[x] > level[y]) swap(x, y);
  int d = level[y] - level[x];
  for (int i = 0; i < K; i++)
    if ((1 << i) & d) y = F[y][i];
  if (x == y) return x;
  for (int i = K - 1; i >= 0; i--) {
    if (F[x][i] != F[y][i]) x = F[x][i], y = F[y][i];
  }
  return F[x][0];
}
long long dist(int x, int y) {
  return level[x] + level[y] - 2 * level[lca(x, y)];
}
bool tk[N];
int fat[N];
int szt[N];
int calcsz(int x, int f) {
  szt[x] = 1;
  for (auto y : g[x])
    if (y != f && !tk[y]) szt[x] += calcsz(y, x);
  return szt[x];
}
void cdfs(int x = 0, int f = -1, int sz = -1) {
  if (sz < 0) sz = calcsz(x, -1);
  for (auto y : g[x])
    if (!tk[y] && szt[y] * 2 >= sz) {
      szt[x] = 0;
      cdfs(y, f, sz);
      return;
    }
  tk[x] = true;
  fat[x] = f;
  for (auto y : g[x])
    if (!tk[y]) cdfs(y, x);
}
void centroid() {
  memset(tk, false, sizeof(tk));
  cdfs();
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0);
  for (int i = 0; i < n; i++) ans[i] = 1E18;
  centroid();
  int cur = 0;
  while (cur != -1) {
    ans[cur] = dist(cur, 0);
    cur = fat[cur];
  }
  while (m--) {
    int t, v;
    cin >> t >> v;
    v--;
    if (t == 1) {
      int cur = v;
      while (cur != -1) {
        ans[cur] = min(ans[cur], dist(cur, v));
        cur = fat[cur];
      }
    } else {
      int cur = v;
      long long res = 1E18;
      while (cur != -1) {
        res = min(res, ans[cur] + dist(cur, v));
        cur = fat[cur];
      }
      cout << res << '\n';
    }
  }
  return 0;
}
