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;
const long long maxn = 3e5 + 100;
const long long mod = 1e9 + 7;
const long long base = 1e15;
vector<long long> adj[maxn];
vector<long long> adj1[maxn];
bool dd[maxn];
long long siz[maxn];
long long cntnw = 0;
long long dinh;
long long anc[maxn][20];
long long dep[maxn];
long long ans[maxn];
void dfs1(long long u, long long par) {
  cntnw++;
  siz[u] = 1;
  for (auto to : adj[u]) {
    if (dd[to] || to == par) continue;
    dfs1(to, u);
    siz[u] += siz[to];
  }
}
void dfs2(long long u, long long par) {
  long long mx = cntnw - siz[u];
  for (auto to : adj[u]) {
    if (dd[to] || to == par) continue;
    dfs2(to, u);
    mx = max(mx, siz[to]);
  }
  if (mx <= cntnw / 2) {
    dinh = u;
  }
}
long long par[maxn];
long long dosth(long long u) {
  cntnw = 0;
  dfs1(u, -1);
  dfs2(u, -1);
  if (cntnw == 1) {
    return dinh;
  }
  dd[dinh] = 1;
  long long p = dinh;
  for (auto to : adj[dinh]) {
    if (dd[to]) continue;
    long long h = dosth(to);
    par[h] = p;
  }
  return p;
}
void dfs(long long u, long long par) {
  anc[u][0] = par;
  for (int i = 1; i <= 18; i++) {
    anc[u][i] = anc[anc[u][i - 1]][i - 1];
  }
  for (auto to : adj[u]) {
    if (to == par) continue;
    dep[to] = dep[u] + 1;
    dfs(to, u);
  }
}
long long lca(long long x, long long y) {
  if (dep[x] < dep[y]) swap(x, y);
  long long kc = dep[x] - dep[y];
  for (int i = 18; i >= 0; i--) {
    if (kc & (1ll << i)) {
      x = anc[x][i];
    }
  }
  if (x == y) return x;
  for (int i = 18; i >= 0; i--) {
    if (anc[x][i] != anc[y][i]) {
      x = anc[x][i];
      y = anc[y][i];
    }
  }
  return anc[x][0];
}
long long kc(long long x, long long y) {
  return dep[x] + dep[y] - 2 * dep[lca(x, y)];
}
void update(long long u, long long rt) {
  ans[u] = min(ans[u], kc(u, rt));
  if (par[u] == 0) return;
  update(par[u], rt);
}
long long get(long long u, long long rt) {
  if (par[u] == 0) return (ans[u] + kc(u, rt));
  return min(ans[u] + kc(u, rt), get(par[u], rt));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  if (fopen("", "r")) {
    freopen(" ", "r", stdin);
    freopen(" ", "w", stdout);
  }
  long long n;
  cin >> n;
  long long q;
  cin >> q;
  for (int i = 1; i <= n - 1; i++) {
    long long x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 0);
  dosth(1);
  for (int i = 1; i <= n; i++) {
    ans[i] = 1e15;
  }
  update(1, 1);
  while (q--) {
    long long t;
    cin >> t;
    if (t == 1) {
      long long v;
      cin >> v;
      update(v, v);
    } else {
      long long x;
      cin >> x;
      cout << get(x, x) << "\n";
    }
  }
}
