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;
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
long long inf = 1e18, MOD = 1e9 + 7;
int n, m, k, ar[1000005], st;
string s, s1;
set<int> g[1000005];
int sub[1000005];
const int LN = 20;
int par[1000005][LN], lev[1000005], adj[1000005];
int nn;
void dfs1(int u, int p) {
  sub[u] = 1;
  nn++;
  for (auto it = g[u].begin(); it != g[u].end(); it++)
    if (*it != p) {
      dfs1(*it, u);
      sub[u] += sub[*it];
    }
}
int dfs2(int u, int p) {
  for (auto it = g[u].begin(); it != g[u].end(); it++)
    if (*it != p && sub[*it] > nn / 2) return dfs2(*it, u);
  return u;
}
void decompose(int root, int p) {
  nn = 0;
  dfs1(root, root);
  int centroid = dfs2(root, root);
  if (p == -1) p = centroid;
  adj[centroid] = p;
  for (auto it = g[centroid].begin(); it != g[centroid].end(); it++) {
    g[*it].erase(centroid);
    decompose(*it, centroid);
  }
  g[centroid].clear();
}
void dfs(long long ver, long long prev_ver, long long dep) {
  par[ver][0] = prev_ver;
  lev[ver] = dep;
  for (auto i : g[ver]) {
    if (i != prev_ver) {
      dfs(i, ver, dep + 1);
    }
  }
}
long long LCA(long long u, long long v) {
  if (lev[u] > lev[v]) swap(u, v);
  long long log_dep = ceil(log2(lev[v]));
  for (long long i = log_dep; i >= 0; i--) {
    if (par[v][i] != -1 && lev[par[v][i]] >= lev[u]) v = par[v][i];
  }
  if (u == v) return v;
  log_dep = ceil(log2(lev[v]));
  for (long long i = log_dep; i >= 0; i--)
    if (par[u][i] != par[v][i]) {
      u = par[u][i];
      v = par[v][i];
    }
  return par[u][0];
}
int dist(int u, int v) { return lev[u] + lev[v] - 2 * lev[LCA(u, v)]; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int ti = 1;
  while (ti--) {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      scanf("%d %d", &u, &v);
      g[u - 1].insert(v - 1);
      g[v - 1].insert(u - 1);
    }
    for (long long i = 0; i < LN; i++)
      for (long long j = 0; j < 1000005; j++) par[j][i] = -1;
    dfs(0, -1, 1);
    for (long long i = 1; i < LN; i++)
      for (long long j = 0; j < n + 1; j++)
        if (par[j][i - 1] != -1) par[j][i] = par[par[j][i - 1]][i - 1];
    decompose(0, -1);
    for (int i = 0; i < n; i++) ar[i] = lev[i] - 1;
    for (int q = 0; q < m; q++) {
      int type, ver;
      scanf("%d %d", &type, &ver);
      ver--;
      if (type == 1) {
        int x = ver;
        while (1) {
          ar[x] = min(ar[x], dist(ver, x));
          if (x == adj[x]) break;
          x = adj[x];
        }
      } else {
        int x = ver;
        int out = ar[x];
        while (1) {
          out = min(out, dist(ver, x) + ar[x]);
          if (x == adj[x]) break;
          x = adj[x];
        }
        printf("%d\n", out);
      }
    }
  }
  return 0;
}
