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 = 0x3f3f3f3f;
const long long int LINF = 0x3f3f3f3f3f3f3f3fll;
const int MAX = (int)1e5 + 10;
const int LOG = 32;
int n;
vector<int> g[MAX];
int pai[MAX];
int sizet[MAX];
bool rev[MAX];
int lvl[MAX];
int t = 0;
int in[MAX], out[MAX];
int dp[MAX][LOG];
int dist[MAX];
void dfs(int u, int p) {
  in[u] = t++;
  for (int e : g[u])
    if (e != p) {
      dp[e][0] = u;
      dfs(e, u);
    }
  out[u] = t;
}
void get_dist(int u, int p, int d) {
  dist[u] = d;
  for (int e : g[u])
    if (e != p) {
      get_dist(e, u, d + 1);
    }
}
void build() {
  for (int i = 0; i < n; i++) {
    dp[i][0] = i;
  }
  t = 0;
  dfs(0, 0);
  for (int k = 1; k < LOG; k++) {
    for (int i = 0; i < n; i++) {
      dp[i][k] = dp[dp[i][k - 1]][k - 1];
    }
  }
  get_dist(0, 0, 0);
}
bool anc(int p, int first) {
  return in[p] <= in[first] and out[first] <= out[p];
}
int lca(int u, int v) {
  if (anc(u, v)) {
    return u;
  }
  if (anc(v, u)) {
    return v;
  }
  for (int k = LOG - 1; ~k; k--) {
    if (!anc(dp[u][k], v)) {
      u = dp[u][k];
    }
  }
  return dp[u][0];
}
int distance(int a, int b) { return dist[a] + dist[b] - (2 * dist[lca(a, b)]); }
int centroid(int u, int p, int size) {
  for (int e : g[u])
    if (e != p and !rev[e]) {
      if (sizet[e] > size / 2) {
        return centroid(e, u, size);
      }
    }
  return u;
}
int get_size(int u, int p) {
  sizet[u] = 1;
  for (int e : g[u])
    if (e != p and !rev[e]) {
      sizet[u] += get_size(e, u);
    }
  return sizet[u];
}
void decomp(int u, int p) {
  get_size(u, u);
  int c = centroid(u, u, sizet[u]);
  rev[c] = true;
  if (u == p) {
    pai[c] = c;
  } else {
    pai[c] = p;
  }
  for (int e : g[c])
    if (!rev[e]) {
      decomp(e, c);
    }
}
int get_lvl(int u) {
  if (lvl[u] != -1) {
    return lvl[u];
  }
  if (pai[u] == u) {
    return lvl[u] = 0;
  }
  return lvl[u] = get_lvl(pai[u]) + 1;
}
void build_centroid() {
  for (int i = 0; i < n; i++) {
    rev[i] = 0;
    lvl[i] = -1;
  }
  decomp(0, 0);
  for (int i = 0; i < n; i++) {
    get_lvl(i);
  }
}
int ans[MAX];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  int q;
  cin >> n >> q;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  build();
  build_centroid();
  memset(ans, INF, sizeof(ans));
  int u = 0;
  int at = u;
  while (at != pai[at]) {
    ans[at] = distance(u, at);
    at = pai[at];
  }
  ans[at] = distance(u, at);
  while (q--) {
    int tt, v;
    cin >> tt >> v;
    v--;
    if (tt == 1) {
      at = v;
      while (at != pai[at]) {
        ans[at] = min(ans[at], distance(at, v));
        at = pai[at];
      }
      ans[at] = min(ans[at], distance(at, v));
    } else {
      at = v;
      int resp = INF;
      while (at != pai[at]) {
        resp = min(resp, ans[at] + distance(at, v));
        at = pai[at];
      }
      resp = min(resp, ans[at] + distance(at, v));
      cout << resp << endl;
    }
  }
  return 0;
}
