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 double PI = acos(-1);
const double eps = 1e-12;
const int inf = 2000000000;
const long long int infLL = (long long int)1e18;
long long int MOD = 1000000007;
int MOD1 = 1000000007;
int MOD2 = 1000000009;
inline bool checkBit(long long int n, long long int i) {
  return n & (1LL << i);
}
inline long long int setBit(long long int n, long long int i) {
  return n | (1LL << i);
  ;
}
inline long long int resetBit(long long int n, long long int i) {
  return n & (~(1LL << i));
}
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool isLeapYear(long long int year) {
  return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
inline void normal(long long int &a) {
  a %= MOD;
  (a < 0) && (a += MOD);
}
inline long long int modMul(long long int a, long long int b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a * b) % MOD;
}
inline long long int modAdd(long long int a, long long int b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a + b) % MOD;
}
inline long long int modSub(long long int a, long long int b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline long long int modPow(long long int b, long long int p) {
  long long int r = 1LL;
  while (p) {
    if (p & 1) r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1LL;
  }
  return r;
}
inline long long int modDiv(long long int a, long long int b) {
  return modMul(a, modPow(b, MOD - 2));
}
bool comp(const pair<long long int, pair<long long int, long long int>> &p1,
          const pair<long long int, pair<long long int, long long int>> &p2) {
  return p1.first > p2.first;
}
bool comp1(const pair<long long int, long long int> &p1,
           const pair<long long int, long long int> &p2) {
  if (p1.first == p2.first) {
    return p1.second > p2.second;
  }
  return p1.first < p2.first;
}
long long int converter(string a) {
  long long int i, mul = 1LL, r, t, ans = 0LL;
  if (a.length() == 0) return 0;
  for (i = a.length() - 1; i >= 0; i--) {
    t = a[i] - '0';
    r = t % 10;
    ans += (mul * r);
    mul = mul * 10;
  }
  return ans;
}
int msb(unsigned x) {
  union {
    double a;
    int b[2];
  };
  a = x;
  return (b[1] >> 20) - 1023;
}
const int MAX = (int)2e5 + 5;
int h[MAX], k_par[MAX][20], n, dp[MAX], cp[MAX];
vector<int> adj[MAX];
void dfs(int u, int cnt, int p) {
  h[u] = cnt;
  k_par[u][0] = p;
  for (auto v : adj[u])
    if (v != p) dfs(v, cnt + 1, u);
}
void build(int x) {
  dfs(x, 0, 0);
  for (int j = 1; (1 << j) <= n; ++j) {
    for (int i = 1; i <= n; ++i)
      if (k_par[i][j - 1] != 0) k_par[i][j] = k_par[k_par[i][j - 1]][j - 1];
  }
}
int lca(int u, int v) {
  if (h[u] < h[v]) swap(u, v);
  for (int i = 19; i >= 0; i--)
    if (k_par[u][i] && h[k_par[u][i]] >= h[v]) u = k_par[u][i];
  if (u == v) return u;
  for (int i = 19; i >= 0; i--)
    if (k_par[u][i] != k_par[v][i]) u = k_par[u][i], v = k_par[v][i];
  return k_par[u][0];
}
int dist(int u, int v) { return h[u] + h[v] - h[lca(u, v)] * 2; }
vector<set<int>> tree;
struct CentroidDecomposition {
  vector<set<int>> tree;
  vector<int> dad, sub;
  CentroidDecomposition(vector<set<int>> &tree) : tree(tree) {
    int n = tree.size();
    dad.resize(n + 1);
    sub.resize(n + 1);
    build(1, 0);
  }
  void build(int u, int p) {
    int n = dfs(u, p);
    int centroid = dfs(u, p, n);
    if (p == 0) p = centroid;
    dad[centroid] = p;
    set<int> temp = tree[centroid];
    for (auto v : temp) {
      tree[centroid].erase(v);
      tree[v].erase(centroid);
      build(v, centroid);
    }
  }
  int dfs(int u, int p) {
    sub[u] = 1;
    for (auto v : tree[u])
      if (v != p) sub[u] += dfs(v, u);
    return sub[u];
  }
  int dfs(int u, int p, int n) {
    for (auto v : tree[u])
      if (v != p and sub[v] > n / 2) return dfs(v, u, n);
    return u;
  }
  int operator[](int i) { return dad[i]; }
};
void getPars() {
  CentroidDecomposition ds = CentroidDecomposition(tree);
  for (int i = 1; i <= n; ++i) cp[i] = ds.dad[i];
}
void update(int u) {
  int v = u;
  while (1) {
    dp[v] = min(dp[v], dist(u, v));
    if (v == cp[v]) break;
    v = cp[v];
  }
}
int query(int u) {
  int ans = inf, v = u;
  while (1) {
    ans = min(ans, dist(v, u) + dp[v]);
    if (cp[v] == v) break;
    v = cp[v];
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int i, x, y, q, tp;
  cin >> n >> q;
  tree.resize(n + 1);
  fill(dp, dp + n + 1, inf);
  for (i = 1; i < n; ++i) {
    cin >> x >> y;
    tree[x].insert(y);
    tree[y].insert(x);
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  getPars();
  build(1);
  update(1);
  for (i = 1; i <= q; ++i) {
    cin >> tp >> x;
    if (tp == 1)
      update(x);
    else
      cout << query(x) << '\n';
  }
  return 0;
}
