#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > AdjList;
vector<int> dist;
vector<int> unused;
void update() {
  queue<int> now;
  for (int i = 0; i < unused.size(); i++) {
    dist[unused[i]] = 0;
    now.push(unused[i]);
  }
  while (!now.empty()) {
    int u = now.front();
    now.pop();
    for (int i = 0; i < AdjList[u].size(); i++) {
      int v = AdjList[u][i];
      if (dist[u] + 1 < dist[v]) {
        dist[v] = dist[u] + 1;
        now.push(v);
      }
    }
  }
  unused.clear();
}
int main() {
  int V, q;
  cin >> V >> q;
  AdjList.assign(V + 1, vector<int>());
  dist.assign(V + 1, -1);
  for (int x, y, i = 0; i < V - 1; i++) {
    cin >> x >> y;
    AdjList[x].push_back(y);
    AdjList[y].push_back(x);
  }
  dist[1] = 0;
  queue<int> now;
  now.push(1);
  while (!now.empty()) {
    int u = now.front();
    now.pop();
    for (int i = 0; i < AdjList[u].size(); i++) {
      int v = AdjList[u][i];
      if (dist[v] == -1) {
        dist[v] = dist[u] + 1;
        now.push(v);
      }
    }
  }
  for (int t, from, i = 0; i < q; i++) {
    cin >> t >> from;
    if (t == 1) {
      unused.push_back(from);
    } else {
      update();
      cout << dist[from] << endl;
    }
  }
  return 0;
}
