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 int inf = (int)1e7;
set<int> g[1000008];
int lvl[1000008], P[1000008][21], sub[1000008];
int parent[1000008], ans[1000008];
int nn = 0;
void dfs_lca(int src, int l) {
  lvl[src] = l;
  for (auto i : g[src]) {
    if (lvl[i] == -1) {
      parent[i] = src;
      dfs_lca(i, l + 1);
    }
  }
}
void preprocess_lca(int root, int N) {
  memset(parent, -1, sizeof(parent));
  memset(lvl, -1, sizeof(lvl));
  dfs_lca(root, 0);
  for (int i = 0; i <= N; ++i) P[i][0] = parent[i];
  for (int j = 1; (1 << j) < N; ++j) {
    for (int i = 1; i <= N; ++i) {
      if (P[i][j - 1] != -1) {
        P[i][j] = P[P[i][j - 1]][j - 1];
      }
    }
  }
}
int lca(int u, int v) {
  if (lvl[u] < lvl[v]) swap(u, v);
  int log = 0;
  while ((1 << log) <= lvl[u]) log++;
  log -= 1;
  for (int i = log; i >= 0; i--) {
    if ((lvl[u] - (1 << i)) >= lvl[v]) {
      u = P[u][i];
    }
  }
  if (u == v) return u;
  for (int i = log; i >= 0; i--) {
    if (P[u][i] != -1 && P[u][i] != P[v][i]) {
      u = P[u][i];
      v = P[v][i];
    }
  }
  return P[u][0];
}
int dist(int u, int v) {
  int l = lca(u, v);
  int ans = lvl[u] + lvl[v] - (2 * lvl[l]);
  return ans;
}
void getSize(int src, int par) {
  sub[src] = 1;
  nn++;
  for (auto i : g[src]) {
    if (i == par) {
      continue;
    }
    getSize(i, src);
    sub[src] += sub[i];
  }
}
int getCentroid(int u, int par) {
  for (auto v : g[u]) {
    if (v != par) {
      if (sub[v] > nn / 2) {
        return getCentroid(v, u);
      }
    }
  }
  return u;
}
void decompose(int u, int par) {
  nn = 0;
  getSize(u, -1);
  int centroid = getCentroid(u, -1);
  parent[centroid] = par;
  for (auto v : g[centroid]) {
    g[v].erase(centroid);
    if (v != par) {
      decompose(v, centroid);
    }
  }
  g[centroid].clear();
}
void update(int u) {
  int x = u;
  while (true) {
    ans[x] = min(ans[x], dist(x, u));
    x = parent[x];
    if (x == -1) {
      break;
    }
  }
}
int query(int u) {
  int ret = inf;
  int x = u;
  while (true) {
    ret = min(ret, ans[x] + dist(u, x));
    x = parent[x];
    if (x == -1) {
      break;
    }
  }
  if (ret == (inf)) {
    ret = -1;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].insert(v);
    g[v].insert(u);
  }
  for (int i = 0; i < 1000008; i++) {
    ans[i] = inf;
  }
  preprocess_lca(1, n);
  decompose(1, -1);
  update(1);
  while (q--) {
    int type, node;
    cin >> type >> node;
    if (type == 1) {
      update(node);
    } else {
      cout << query(node) << endl;
    }
  }
  return 0;
}
