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;
long long maximum(long long x, long long y) {
  if (x > y) return x;
  return y;
}
long long minimum(long long x, long long y) {
  if (x < y) return x;
  return y;
}
void print_vector(vector<int> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " ";
  cout << '\n';
}
void print_vector(vector<long long> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " ";
  cout << '\n';
}
void print_vector(vector<double> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " ";
  cout << '\n';
}
void print_vector(vector<string> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " ";
  cout << '\n';
}
void print_vector(vector<bool> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " ";
  cout << '\n';
}
void print_vector(vector<pair<int, int>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << (*i).first << " ";
  cout << '\n';
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << (*i).second << " ";
  cout << '\n';
}
void print_vector(vector<pair<long long, long long>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << (*i).first << " ";
  cout << '\n';
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << (*i).second << " ";
  cout << '\n';
}
void print_vector(vector<pair<pair<int, int>, int>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << (*i).first.first << " " << (*i).first.second << " " << (*i).second
         << '\n';
  cout << '\n';
}
void print_vector(vector<pair<int, pair<int, int>>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << (*i).first << " " << (*i).second.first << " " << (*i).second.second
         << '\n';
  cout << '\n';
}
void print_vector(vector<vector<string>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    print_vector(*i);
    cout << '\n';
  }
  cout << '\n';
}
void print_vector(vector<vector<int>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    cout << i - amount.begin() << '\n';
    print_vector(*i);
    cout << '\n';
  }
  cout << '\n';
}
void print_vector(vector<vector<long long>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    cout << i - amount.begin() << '\n';
    print_vector(*i);
    cout << '\n';
  }
  cout << '\n';
}
void print_vector(vector<vector<pair<long long, long long>>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    cout << i - amount.begin() << '\n';
    print_vector(*i);
  }
  cout << '\n';
}
void print_vector(vector<vector<vector<int>>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    cout << i - amount.begin() << '\n';
    print_vector(*i);
    cout << '\n';
  }
  cout << '\n';
}
void print_vector(vector<vector<vector<long long>>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    cout << i - amount.begin() << '\n';
    print_vector(*i);
    cout << '\n';
  }
  cout << '\n';
}
void print_vector(vector<vector<bool>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    print_vector(*i);
    cout << '\n';
  }
  cout << '\n';
}
void print_set(set<int> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " ";
  cout << '\n';
}
void print_set(set<pair<int, int>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++)
    cout << i->first << " " << i->second << '\n';
  cout << '\n';
}
void print_vector(vector<set<int>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    cout << i - amount.begin() << '\n';
    print_set(*i);
    cout << '\n';
  }
  cout << '\n';
}
void print_vector(vector<vector<pair<int, int>>> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) {
    cout << i - amount.begin() << '\n';
    print_vector(*i);
  }
}
void print_set(set<string> amount) {
  for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " ";
  cout << '\n';
}
void print_map(map<int, vector<int>> m) {
  for (map<int, vector<int>>::iterator i = m.begin(); i != m.end(); i++) {
    cout << i->first << " ";
    print_vector(i->second);
  }
}
void print_map(map<string, vector<string>> m) {
  for (map<string, vector<string>>::iterator i = m.begin(); i != m.end(); i++) {
    cout << i->first << " ";
    print_vector(i->second);
  }
}
void print_map(map<string, int> m) {
  for (auto i = m.begin(); i != m.end(); i++) {
    cout << i->first << " " << i->second << '\n';
  }
}
void print_map(map<string, vector<bool>> m) {
  for (map<string, vector<bool>>::iterator i = m.begin(); i != m.end(); i++) {
    cout << i->first << " ";
    print_vector(i->second);
  }
}
void print_map(map<string, set<string>> m) {
  for (auto i = m.begin(); i != m.end(); i++) {
    cout << i->first << " ";
    print_set(i->second);
  }
}
void print_map(map<int, int> m) {
  for (map<int, int>::iterator i = m.begin(); i != m.end(); i++) {
    cout << i->first << " " << i->second << '\n';
  }
}
void print_map(map<char, vector<string>> m) {
  for (auto i = m.begin(); i != m.end(); i++) {
    cout << i->first << '\n';
    cout << '\t';
    print_vector(i->second);
  }
}
void print_map(map<char, int> m) {
  for (auto i = m.begin(); i != m.end(); i++) {
    cout << i->first << '\n';
    cout << '\t' << i->second << '\n';
  }
}
void print_map(map<pair<int, int>, int> m) {
  for (auto i = m.begin(); i != m.end(); i++) {
    cout << i->first.first << " " << i->first.second << " " << i->second
         << '\n';
  }
}
bool comp(pair<int, int> x, pair<int, int> y) {
  if (x.second == y.second) return x.first < y.first;
  return x.second < y.second;
}
struct Graph {
  int V, E;
  vector<pair<int, pair<int, int>>> edges;
  Graph(int a, int b) {
    V = a;
    E = b;
  }
  void addEdge(int a, int b, int w) { edges.push_back({w, {a, b}}); }
  vector<int> links, sizes;
  int find(int a) {
    if (a == links[a]) return a;
    return links[a] = find(links[a]);
  }
  bool same(int a, int b) { return find(a) == find(b); }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (sizes[a] < sizes[b]) swap(a, b);
    sizes[a] += sizes[b];
    links[b] = a;
  }
  void sort_edges() { sort(edges.begin(), edges.end()); }
  long long kruskalMST() {
    sort_edges();
    links.resize(V);
    sizes.resize(V);
    for (int i = 0; i < V; i++) {
      links[i] = i;
      sizes[i] = 1;
    }
    long long sum = 0;
    int count = 0;
    for (int i = (0); i < (E); ++i) {
      int start = edges[i].second.first;
      int end = edges[i].second.second;
      if (!same(start, end)) {
        unite(start, end);
        sum += edges[i].first;
        count++;
      }
    }
    if (count != V - 1) return -1000000007;
    return sum;
  }
};
int modInverse(int a, int m) {
  int m0 = m;
  int y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    int q = a / m;
    int t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long power(long long number, int power, int mod) {
  long long ans = 1;
  while (number) {
    if (((number - 1) & 1) == 0) {
      ans *= power;
      ans %= mod;
      ans *= ans;
      ans %= mod;
      number--;
      number >>= 1;
    } else {
      ans *= ans;
      ans %= mod;
      number >>= 1;
    }
  }
  return ans;
}
long double area(pair<int, int> x, pair<int, int> y, pair<int, int> z) {
  return ((long long)x.second * y.first + (long long)y.second * z.first +
          (long long)z.second * x.first - (long long)x.first * y.second -
          (long long)y.first * z.second - (long long)z.first * x.second) /
         2.0;
}
bool clockwise(pair<int, int> x, pair<int, int> y, pair<int, int> z) {
  return area(x, y, z) > 0;
}
int gcd(int a, int b) {
  if (a > b) swap(a, b);
  if (a == 0) return b;
  return gcd(a, b % a);
}
long long a, b, c;
void setIO(string second) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
int n, m;
vector<vector<int>> adjacency;
void init() {
  setIO("");
  cin >> n >> m;
  adjacency.resize(n);
  for (int i = (0); i < (n - 1); ++i) {
    cin >> a >> b;
    adjacency[--a].push_back(--b);
    adjacency[b].push_back(a);
  }
}
vector<int> dist;
vector<int> red;
void update() {
  fill(dist.begin(), dist.end(), 1000000007);
  for (auto& x : red) dist[x] = 0;
  list<int> todo;
  for (auto& x : red) todo.push_back(x);
  while (!todo.empty()) {
    int index = todo.front();
    todo.pop_front();
    for (auto& x : adjacency[index]) {
      if (dist[x] > 1 + dist[index]) {
        todo.push_back(x);
        dist[x] = 1 + dist[index];
      }
    }
  }
}
vector<int> parents;
vector<int> tin;
vector<int> tout;
vector<int> depth;
void dfs(int index) {
  tin[index] = a;
  a++;
  for (auto& x : adjacency[index])
    if (tin[x] == -1) {
      depth[x] = depth[index] + 1;
      parents[x] = index;
      dfs(x);
    }
  tout[index] = a;
  a++;
}
vector<vector<int>> jump;
int logh;
bool is_ancestor(int anc, int node) {
  return tin[anc] <= tin[node] && tout[anc] >= tout[node];
}
int LCA(int x, int y) {
  if (depth[x] > depth[y]) swap(x, y);
  if (is_ancestor(x, y)) return x;
  int j = logh - 1;
  int next;
  while (!is_ancestor(parents[x], y)) {
    next = jump[x][j];
    if (next == -1 || is_ancestor(next, y)) {
      j--;
    } else {
      x = next;
    }
  }
  return parents[x];
}
int main() {
  init();
  parents.resize(n);
  parents[0] = -1;
  tin.resize(n, -1);
  tout.resize(n);
  depth.resize(n);
  a = 0;
  dfs(0);
  int h = *max_element(depth.begin(), depth.end());
  logh = log2(h - 1) + 1;
  jump.resize(n);
  for (int i = (0); i < (n); ++i) jump[i].resize(logh + 1);
  for (int i = (0); i < (n); ++i) jump[i][0] = parents[i];
  for (int i = (1); i < (logh + 1); ++i)
    for (int j = (0); j < (n); ++j) {
      a = jump[j][i - 1];
      if (a != -1)
        jump[j][i] = jump[a][i - 1];
      else
        jump[j][i] = -1;
    }
  vector<int> todo;
  red.push_back(0);
  dist.resize(n);
  update();
  int sqrt_m = sqrt(m - 1) + 1;
  for (int i = (0); i < (m); ++i) {
    cin >> a >> b;
    b--;
    if (a == 1) {
      red.push_back(b);
      todo.push_back(b);
    } else {
      int val = dist[b];
      for (auto& x : todo) {
        int lca = LCA(b, x);
        c = depth[x] + depth[b] - 2 * depth[lca];
        if (c < val) val = c;
      }
      cout << val << '\n';
    }
    if ((i - 1) % sqrt_m == 0) {
      update();
      todo.resize(0);
    }
  }
}
