Xenia the programmer has a tree consisting of n nodes. We will consider the tree nodes indexed from 1 to n. We will also consider the first node to be initially painted red, and the other nodes — to be painted blue.

The distance between two tree nodes v and u is the number of edges in the shortest path between v and u.

Xenia needs to learn how to quickly execute queries of two types:

  1. paint a specified blue node in red; 
  2. calculate which red node is the closest to the given one and print the shortest distance to the closest red node. 



Your task is to write a program which will execute the described queries.

Input

The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of nodes in the tree and the number of queries. Next n - 1 lines contain the tree edges, the i-th line contains a pair of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — an edge of the tree.

Next m lines contain queries. Each query is specified as a pair of integers ti, vi (1 ≤ ti ≤ 2, 1 ≤ vi ≤ n). If ti = 1, then as a reply to the query we need to paint a blue node vi in red. If ti = 2, then we should reply to the query by printing the shortest distance from some red node to node vi.

It is guaranteed that the given graph is a tree and that all queries are correct.

Output

For each second type query print the reply in a single line.

Examples

Input

5 4
1 2
2 3
2 4
4 5
2 1
2 5
1 2
2 5


Output

0
3
2
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long INF = 1e18;
const int inf = 1e9;
const int N = 2e5 + 5;
const long long mod = 998244353;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
int deepth[N], p[N], w[N], top[N], check[N];
vector<int> g[N], ans(N, inf);
vector<pair<int, int> > q[N];
void dfs(int v = 0, int p = -1, int d = 0) {
  deepth[v] = d;
  for (int i : g[v]) {
    if (i != p) {
      dfs(i, v, d + 1);
    }
  }
}
int find_set(int a) { return a == p[a] ? a : p[a] = find_set(p[a]); }
void union_sets(int a, int b, int c) {
  a = find_set(a), b = find_set(b);
  if (w[a] < w[b]) {
    swap(a, b);
  }
  p[b] = a;
  w[a] += w[b];
  top[a] = c;
}
void taryan(int v = 0) {
  check[v] = 1;
  p[v] = v;
  w[v] = 1;
  top[v] = v;
  for (int i : g[v]) {
    if (!check[i]) {
      taryan(i);
      union_sets(v, i, v);
    }
  }
  for (pair<int, int> i : q[v]) {
    if (check[i.first]) {
      ans[i.second] =
          min(ans[i.second],
              deepth[v] + deepth[i.first] - 2 * deepth[top[find_set(i.first)]]);
    }
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs();
  int b = sqrt(m), num = 0, num_q = 0;
  vector<int> red, type(m), a(m);
  for (int i = 0; i < m; i++) {
    cin >> type[i] >> a[i];
    a[i]--;
    num++;
    if (num > b) {
      num = 1;
      red.clear();
    }
    if (type[i] == 1) {
      red.push_back(a[i]);
    } else {
      num_q++;
      for (int j = 0; j < red.size(); j++) {
        q[red[j]].push_back({a[i], num_q});
        q[a[i]].push_back({red[j], num_q});
      }
    }
  }
  taryan();
  red.clear();
  num = 0;
  vector<int> dist(n), color(n, 0);
  color[0] = 1;
  num_q = 0;
  for (int i = 0; i < m; i++) {
    num++;
    if (num > b) {
      num = 1;
    }
    if (num == 1) {
      red.clear();
      queue<int> q;
      for (int i = 0; i < n; i++) {
        dist[i] = inf;
        if (color[i]) {
          q.push(i);
          dist[i] = 0;
        }
      }
      while (!q.empty()) {
        int v = q.front();
        for (int j : g[v]) {
          if (dist[j] == inf) {
            dist[j] = dist[v] + 1;
            q.push(j);
          }
        }
        q.pop();
      }
    }
    if (type[i] == 1) {
      red.push_back(a[i]);
      color[a[i]] = 1;
    } else {
      num_q++;
      cout << min(dist[a[i]], ans[num_q]) << '\n';
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
