#include <bits/stdc++.h>
using namespace std;
template <class T>
bool remin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool remax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int nxt() {
  int first;
  scanf("%d", &first);
  return first;
}
long long gcd(long long a, long long b) {
  a = abs(a);
  b = abs(b);
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
struct pt {
  long double first, second, z;
  pt() {}
  pt(long double first, long double second, long double z)
      : first(first), second(second), z(z) {}
  inline pt operator-(const pt &r) const {
    return pt(first - r.first, second - r.second, z - r.z);
  }
  inline pt operator+(const pt &r) const {
    return pt(first + r.first, second + r.second, z + r.z);
  }
  inline pt operator*(const long double &r) const {
    return pt(first * r, second * r, z * r);
  }
  inline long double sqlen() const {
    return abs(first * first + second * second + z * z);
  }
  long double len() const { return sqrtl(sqlen()); }
  inline bool operator<(const pt &r) const {
    if (first != r.first) return first < r.first;
    return second < r.second;
  }
  inline bool operator==(const pt &r) const {
    return first == r.first && second == r.second;
  }
};
ostream &operator<<(ostream &os, const pt &p) {
  return os << "(" << p.first << "," << p.second << ")";
}
inline pt cross(const pt &l, const pt &r) {
  return pt(l.second * r.z - l.z * r.second, l.z * r.first - l.first * r.z,
            l.first * r.second - l.second * r.first);
}
inline long double dot(const pt &l, const pt &r) {
  return l.first * r.first + l.second * r.second + l.z * r.z;
}
long long pwmod(long long a, long long n, long long mod) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret = ret * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ret;
}
template <typename T>
inline T sqr(T first) {
  return first * first;
}
bool remin(long long &first, long long second) {
  if (first > second) {
    first = second;
    return 1;
  }
  return 0;
}
const int N = 300 * 1000;
vector<int> g[N];
int size[N];
int parent[N];
int answer[N];
int maxSize[N];
vector<int> childs_[N];
void dfs(int v, int p = -1) {
  size[v] = 1;
  parent[v] = p;
  for (int to : g[v]) {
    if (to == p) continue;
    dfs(to, v);
    size[v] += size[to];
  }
  maxSize[v] = 0;
  for (int to : g[v]) {
    if (to == p) continue;
    remax(maxSize[v], size[to]);
  }
}
void dfs2(int v, int p = -1) {
  vector<int> &ch = childs_[v];
  for (int to : g[v]) {
    if (to == p) continue;
    dfs2(to, v);
    ch.push_back(answer[to]);
  }
  if (ch.empty()) {
    answer[v] = v;
    return;
  }
  for (int &u : ch) {
    int s = size[v] / 2;
    while (u != v && maxSize[parent[u]] <= s) {
      u = parent[u];
    }
  }
  for (int u : ch) {
    int s = size[v] / 2;
    int top = size[v] - size[u];
    if (maxSize[u] <= s && top <= s) {
      answer[v] = u;
    }
  }
}
void solve() {
  int n = nxt();
  int q = nxt();
  for (int i = 1; i < n; ++i) {
    int p = nxt() - 1;
    g[p].push_back(i);
    g[i].push_back(p);
  }
  dfs(0);
  dfs2(0);
  for (int i = 0; i < (int)(q); i++) {
    int v = nxt() - 1;
    cout << answer[v] + 1 << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  for (int i = 0; i < (int)(t); i++) {
    solve();
  }
  return 0;
}

### Prompt

Please formulate a cpp solution to the following problem:

After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of the roses. Now he likes to watch snowflakes.

Once upon a time, he found a huge snowflake that has a form of the tree (connected acyclic graph) consisting of n nodes. The root of tree has index 1. Kay is very interested in the structure of this tree.

After doing some research he formed q queries he is interested in. The i-th query asks to find a centroid of the subtree of the node vi. Your goal is to answer all queries.

Subtree of a node is a part of tree consisting of this node and all it's descendants (direct or not). In other words, subtree of node v is formed by nodes u, such that node v is present on the path from u to root.

Centroid of a tree (or a subtree) is a node, such that if we erase it from the tree, the maximum size of the connected component will be at least two times smaller than the size of the initial tree (or a subtree).

Input

The first line of the input contains two integers n and q (2 ≤ n ≤ 300 000, 1 ≤ q ≤ 300 000) — the size of the initial tree and the number of queries respectively.

The second line contains n - 1 integer p2, p3, ..., pn (1 ≤ pi ≤ n) — the indices of the parents of the nodes from 2 to n. Node 1 is a root of the tree. It's guaranteed that pi define a correct tree.

Each of the following q lines contain a single integer vi (1 ≤ vi ≤ n) — the index of the node, that define the subtree, for which we want to find a centroid.

Output

For each query print the index of a centroid of the corresponding subtree. If there are many suitable nodes, print any of them. It's guaranteed, that each subtree has at least one centroid.

Example

Input

7 4
1 1 3 3 5 3
1
2
3
5


Output

3
2
3
6

Note

<image>

The first query asks for a centroid of the whole tree — this is node 3. If we delete node 3 the tree will split in four components, two of size 1 and two of size 2.

The subtree of the second node consists of this node only, so the answer is 2.

Node 3 is centroid of its own subtree.

The centroids of the subtree of the node 5 are nodes 5 and 6 — both answers are considered correct.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool remin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool remax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int nxt() {
  int first;
  scanf("%d", &first);
  return first;
}
long long gcd(long long a, long long b) {
  a = abs(a);
  b = abs(b);
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
struct pt {
  long double first, second, z;
  pt() {}
  pt(long double first, long double second, long double z)
      : first(first), second(second), z(z) {}
  inline pt operator-(const pt &r) const {
    return pt(first - r.first, second - r.second, z - r.z);
  }
  inline pt operator+(const pt &r) const {
    return pt(first + r.first, second + r.second, z + r.z);
  }
  inline pt operator*(const long double &r) const {
    return pt(first * r, second * r, z * r);
  }
  inline long double sqlen() const {
    return abs(first * first + second * second + z * z);
  }
  long double len() const { return sqrtl(sqlen()); }
  inline bool operator<(const pt &r) const {
    if (first != r.first) return first < r.first;
    return second < r.second;
  }
  inline bool operator==(const pt &r) const {
    return first == r.first && second == r.second;
  }
};
ostream &operator<<(ostream &os, const pt &p) {
  return os << "(" << p.first << "," << p.second << ")";
}
inline pt cross(const pt &l, const pt &r) {
  return pt(l.second * r.z - l.z * r.second, l.z * r.first - l.first * r.z,
            l.first * r.second - l.second * r.first);
}
inline long double dot(const pt &l, const pt &r) {
  return l.first * r.first + l.second * r.second + l.z * r.z;
}
long long pwmod(long long a, long long n, long long mod) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret = ret * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ret;
}
template <typename T>
inline T sqr(T first) {
  return first * first;
}
bool remin(long long &first, long long second) {
  if (first > second) {
    first = second;
    return 1;
  }
  return 0;
}
const int N = 300 * 1000;
vector<int> g[N];
int size[N];
int parent[N];
int answer[N];
int maxSize[N];
vector<int> childs_[N];
void dfs(int v, int p = -1) {
  size[v] = 1;
  parent[v] = p;
  for (int to : g[v]) {
    if (to == p) continue;
    dfs(to, v);
    size[v] += size[to];
  }
  maxSize[v] = 0;
  for (int to : g[v]) {
    if (to == p) continue;
    remax(maxSize[v], size[to]);
  }
}
void dfs2(int v, int p = -1) {
  vector<int> &ch = childs_[v];
  for (int to : g[v]) {
    if (to == p) continue;
    dfs2(to, v);
    ch.push_back(answer[to]);
  }
  if (ch.empty()) {
    answer[v] = v;
    return;
  }
  for (int &u : ch) {
    int s = size[v] / 2;
    while (u != v && maxSize[parent[u]] <= s) {
      u = parent[u];
    }
  }
  for (int u : ch) {
    int s = size[v] / 2;
    int top = size[v] - size[u];
    if (maxSize[u] <= s && top <= s) {
      answer[v] = u;
    }
  }
}
void solve() {
  int n = nxt();
  int q = nxt();
  for (int i = 1; i < n; ++i) {
    int p = nxt() - 1;
    g[p].push_back(i);
    g[i].push_back(p);
  }
  dfs(0);
  dfs2(0);
  for (int i = 0; i < (int)(q); i++) {
    int v = nxt() - 1;
    cout << answer[v] + 1 << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  for (int i = 0; i < (int)(t); i++) {
    solve();
  }
  return 0;
}

```