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>
using namespace std;
set<long long> g[100005];
long long logN = 20;
long long dp[100005][20];
long long level[100005];
long long cnt[100005];
long long par[100005];
long long ans[100005];
void dfs1(long long src, long long p) {
  for (set<long long>::iterator it = g[src].begin(); it != g[src].end(); it++) {
    if (*it != p) {
      dp[*it][0] = src;
      level[*it] = 1 + level[src];
      dfs1(*it, src);
    }
  }
}
long long n;
void preprocess() {
  dp[1][0] = 1;
  for (long long i = 1; i < logN; i++) {
    for (long long j = 1; j <= n; j++) {
      dp[j][i] = dp[dp[j][i - 1]][i - 1];
    }
  }
}
long long lca(long long a, long long b) {
  if (level[a] > level[b]) swap(a, b);
  long long d = level[b] - level[a];
  long long t = b;
  for (long long i = 0; i < logN; i++) {
    if (d & (1LL << i)) {
      b = dp[b][i];
    }
  }
  if (a == b) return a;
  for (long long i = logN - 1; i >= 0; i--) {
    if (dp[a][i] != dp[b][i]) a = dp[a][i], b = dp[b][i];
  }
  return dp[a][0];
}
long long dis(long long u, long long v) {
  return level[u] + level[v] - 2 * level[lca(u, v)];
}
long long nn;
void dfs2(long long src, long long p) {
  nn++;
  cnt[src] = 1;
  for (set<long long>::iterator it = g[src].begin(); it != g[src].end(); it++) {
    if (*it != p) {
      dfs2(*it, src);
      cnt[src] += cnt[*it];
    }
  }
}
long long dfs3(long long src, long long p) {
  for (set<long long>::iterator it = g[src].begin(); it != g[src].end(); it++) {
    if (*it != p && cnt[*it] > nn / 2) return dfs3(*it, src);
  }
  return src;
}
void decompose(long long src, long long p) {
  nn = 0;
  dfs2(src, src);
  long long centroid = dfs3(src, src);
  if (p == -1) p = centroid;
  par[centroid] = p;
  for (set<long long>::iterator it = g[centroid].begin();
       it != g[centroid].end(); it++) {
    g[*it].erase(centroid);
    decompose(*it, centroid);
  }
  g[centroid].clear();
}
void update(long long u) {
  long long x = u;
  ans[u] = 0;
  while (1) {
    ans[x] = min(ans[x], dis(u, x) + ans[u]);
    if (x == par[x]) break;
    x = par[x];
  }
}
long long query(long long u) {
  long long x = u;
  long long res = INT_MAX;
  while (1) {
    res = min(res, dis(u, x) + ans[x]);
    if (x == par[x]) break;
    x = par[x];
  }
  return res;
}
signed main() {
  for (long long i = 1; i <= 100000; i++) ans[i] = INT_MAX;
  long long m;
  cin >> n >> m;
  for (long long i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    g[u].insert(v);
    g[v].insert(u);
  }
  dfs1(1, -1);
  preprocess();
  decompose(1, -1);
  update(1);
  while (m--) {
    long long t, v;
    cin >> t >> v;
    if (t == 1) {
      update(v);
    } else {
      cout << query(v) << "\n";
    }
  }
  return 0;
}
