#include <bits/stdc++.h>
namespace XX {
template <int BLOCKSIZE>
class MemoryManager {
 public:
  static constexpr const int INIT =
      1024 * 1024 / BLOCKSIZE ? 1024 * 1024 / BLOCKSIZE : 1;
  static MemoryManager* inst() {
    static MemoryManager ret;
    return &ret;
  }
  void* alloc() {
    void* ret;
    if (_ptr) {
      ret = _ptr;
      _ptr = *static_cast<void**>(_ptr);
    } else {
      if (_pos == _size) {
        _pos = 0;
        _buf[++_idx] = new char[_size <<= 1];
      }
      ret = _buf[_idx] + _pos;
      _pos += BLOCKSIZE;
    }
    return ret;
  }
  void dealloc(void* p) {
    *static_cast<void**>(p) = _ptr;
    _ptr = p;
  }
  ~MemoryManager() {
    for (int i = 1; i <= _idx; i++) delete[] _buf[i];
  }

 private:
  MemoryManager() { _buf[0] = _init; }
  char _init[INIT * BLOCKSIZE];
  int _size = INIT * BLOCKSIZE;
  int _idx = 0;
  int _pos = 0;
  char* _buf[32] = {};
  void* _ptr = nullptr;
};
template <typename T>
struct BlockAllocater {
  void* operator new(std::size_t count) {
    return MemoryManager<sizeof(T)>::inst()->alloc();
  }
  void operator delete(void* ptr) {
    return MemoryManager<sizeof(T)>::inst()->dealloc(ptr);
  }
};
template <typename T>
struct NullNode {
  static T nullnode;
  static T* null() { return &nullnode; }
  bool isNull() { return this == null(); }
};
template <typename T>
T NullNode<T>::nullnode;
}  // namespace XX
namespace XX {
template <typename... EdgeTs>
class Graph {
 public:
  struct Edge : public EdgeTs... {
    int from, to;
    Edge(int f, int t, EdgeTs... args) : from(f), to(t), EdgeTs(args)... {}
    Edge() {}
  };
  struct Node : public Edge, BlockAllocater<Node> {
    Node* next;
    template <typename... Args>
    Node(Node* nn, Args... args) : next(nn), Edge(args...) {}
  };
  typedef Node* EdgeIdx;

 private:
  std::vector<Node*> _adj;
  int _numVertex;
  void _dealloc(Node* node) {
    if (node) {
      _dealloc(node->next);
      delete node;
    }
  }

 public:
  Graph(int v = 0) : _adj(v) {}
  int size() { return _adj.size(); }
  void resize(int size) { _adj.resize(size); }
  EdgeIdx add(int from, int to, EdgeTs... args) {
    return _adj[from] = new Node{_adj[from], from, to, args...};
  }
  Node& operator[](EdgeIdx idx) { return idx->e; }
  struct Enumerator {
    struct It {
      Node* ptr;
      Node& operator*() { return *ptr; }
      void operator++() { ptr = ptr->next; }
      bool operator!=(const It& other) { return ptr != other.ptr; }
    } b, e;
    It begin() { return b; }
    It end() { return e; }
  };
  struct AllEnumerator {
    struct It {
      Node* ptr;
      int v;
      Graph& g;
      Node& operator*() { return *ptr; }
      void operator++() {
        ptr = ptr->next;
        while (!ptr && ++v < g.size()) ptr = g._adj[v];
      }
      bool operator!=(const It& other) { return ptr != other.ptr; }
    };
    Graph& g;
    It begin() {
      for (int i = 0; i < g.size(); i++)
        if (g._adj[i]) return {g._adj[i], i, g};
      return end();
    }
    It end() { return {nullptr, 0, g}; }
  };
  Enumerator adj(int v) { return {_adj[v], nullptr}; }
  Enumerator adj(EdgeIdx idx) { return {idx, nullptr}; }
  AllEnumerator edges() { return {*this}; }
  Enumerator operator[](int idx) { return adj(idx); }
};
}  // namespace XX
template <typename T>
struct ScanfSpecifier {};
template <>
struct ScanfSpecifier<int> {
  static constexpr const char* value = "%d";
};
template <>
struct ScanfSpecifier<double> {
  static constexpr const char* value = "%lf";
};
template <>
struct ScanfSpecifier<float> {
  static constexpr const char* value = "%f";
};
template <>
struct ScanfSpecifier<char> {
  static constexpr const char* value = "%c";
};
template <>
struct ScanfSpecifier<const char*> {
  static constexpr const char* value = "%s";
};
template <>
struct ScanfSpecifier<unsigned long> {
  static constexpr const char* value = "%lu";
};
template <>
struct ScanfSpecifier<char*> {
  static constexpr const char* value = "%s";
};
template <>
struct ScanfSpecifier<unsigned int> {
  static constexpr const char* value = "%u";
};
template <>
struct ScanfSpecifier<long long int> {
  static constexpr const char* value = "%lld";
};
template <typename T>
int RD(T& arg) {
  return std::scanf(ScanfSpecifier<T>::value, &arg);
}
template <int S>
int RD(char (&arg)[S]) {
  return std::scanf("%s", arg);
}
template <>
int RD<char*>(char*& arg) {
  return std::scanf("%s", arg);
}
template <>
int RD<char>(char& arg) {
  return std::scanf(" %c", &arg);
}
template <typename T, typename... Args>
int RD(T& arg1, Args&... args) {
  return RD(arg1) + RD(args...);
}
template <typename T>
T RD() {
  T ret;
  RD(ret);
  return ret;
}
template <typename It>
void RDV(It begin, It end) {
  while (begin != end) RD(*begin++);
}
template <typename C>
void RDV(C& c) {
  RDV(std::begin(c), std::end(c));
}
template <typename... Args>
void WT(Args... args) {
  int alc = 0;
  int dummy[] = {((alc++ ? std::printf(" ") : 0),
                  std::printf(ScanfSpecifier<Args>::value, args), 0)...};
}
template <typename... Args>
void WTL(Args... args) {
  WT(args...);
  std::printf("\n");
}
template <typename It>
void WTV(It begin, It end) {
  int alc = 0;
  while (begin != end) (alc++ ? std::printf(" ") : 0), WT(*begin++);
}
template <typename C>
void WTV(const C& c) {
  WTV(std::begin(c), std::end(c));
}
template <typename It>
void WTVL(It begin, It end) {
  WTV(begin, end);
  std::printf("\n");
}
template <typename C>
void WTVL(const C& c) {
  WTVL(std::begin(c), std::end(c));
}
namespace XX {
template <template <typename> class Compare, typename T>
inline T& UP(T& x, const T& y) {
  if (Compare<T>()(y, x)) x = y;
  return x;
}
template <typename Compare, typename T>
inline T& UP(T& x, const T& y, Compare comp) {
  if (comp(y, x)) x = y;
  return x;
}
template <typename T>
inline T& GT(T& x, const T& y) {
  return UP<std::greater>(x, y);
}
template <typename T>
inline T& LS(T& x, const T& y) {
  return UP<std::less>(x, y);
}
template <typename T>
struct Mapper {
  int operator[](const T& v) {
    int& ret = table[v];
    if (!ret) rtable[ret = table.size()] = v;
    return ret - 1;
  }
  template <typename... Args>
  int operator()(Args... args) {
    return (*this)[T(args...)];
  }
  T rev(int idx) { return rtable[idx + 1]; }
  std::map<T, int> table;
  std::map<int, T> rtable;
};
template <typename T, int S>
struct ReferenceArray {
  struct It {
    typename std::array<T*, S>::iterator it;
    T& operator*() { return **it; }
    void operator++() { it++; }
    bool operator!=(const It& other) { return it != other.it; }
  };
  int size() const { return _ptr.size(); }
  It begin() const { return {_ptr.begin()}; }
  It end() const { return {_ptr.end()}; }
  T& operator[](int idx) const { return *_ptr[idx]; }
  mutable std::array<T*, S> _ptr;
};
template <typename T, typename... Args>
ReferenceArray<T, sizeof...(Args) + 1> MAKEV(T& arg1, Args&... args) {
  return {&arg1, &args...};
}
struct Range {
  struct It {
    int num, step;
    int operator*() { return num; }
    void operator++() { num += step; }
    bool operator!=(const It& other) { return num != other.num; }
  };
  Range(int ee) : b(0), e(ee) {}
  Range(int bb, int ee) : b(bb), e(ee) {}
  It begin() { return {b, (b < e ? 1 : -1)}; }
  It end() { return {e, 0}; }
  int b, e;
};
}  // namespace XX
using XX::Graph;
template <typename T>
T& UMAX(T& x, T y) {
  return XX::UP<std::greater>(x, y);
}
template <typename T>
T& UMIN(T& x, T y) {
  return XX::UP<std::less>(x, y);
}
using XX::UP;
using RG = XX::Range;
using XX::MAKEV;
using XX::Mapper;
using namespace std;
int N, Q;
Graph<> tree;
vector<int> qs[500000];
int ans[500000];
int amt[500000];
int dfs(int n) {
  amt[n] = 1;
  for (auto& e : tree[n]) amt[n] += dfs(e.to);
  return amt[n];
}
set<pair<int, int>> table;
void dfs2(int u) {
  for (auto& q : qs[u]) table.emplace(amt[u], q);
  int sum = 0;
  int mx = 0;
  for (auto& e : tree[u]) {
    sum += amt[e.to];
    UMAX(mx, amt[e.to]);
  }
  auto l = table.lower_bound({mx * 2, 0});
  auto r = table.lower_bound({sum * 2 + 2 + 1, 0});
  for (auto it = l; it != r; it++) ans[it->second] = u + 1;
  table.erase(l, r);
  for (auto& e : tree[u]) dfs2(e.to);
}
int main() {
  RD(N, Q);
  tree.resize(N);
  for (int i = 1; i < N; i++) {
    int p;
    RD(p);
    tree.add(p - 1, i);
  }
  for (int i = 0; i < Q; i++) {
    int v;
    RD(v);
    qs[v - 1].push_back(i);
  }
  dfs(0);
  dfs2(0);
  for (int i = 0; i < Q; i++) WTL(ans[i]);
}

### Prompt

Your task is to create 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>
namespace XX {
template <int BLOCKSIZE>
class MemoryManager {
 public:
  static constexpr const int INIT =
      1024 * 1024 / BLOCKSIZE ? 1024 * 1024 / BLOCKSIZE : 1;
  static MemoryManager* inst() {
    static MemoryManager ret;
    return &ret;
  }
  void* alloc() {
    void* ret;
    if (_ptr) {
      ret = _ptr;
      _ptr = *static_cast<void**>(_ptr);
    } else {
      if (_pos == _size) {
        _pos = 0;
        _buf[++_idx] = new char[_size <<= 1];
      }
      ret = _buf[_idx] + _pos;
      _pos += BLOCKSIZE;
    }
    return ret;
  }
  void dealloc(void* p) {
    *static_cast<void**>(p) = _ptr;
    _ptr = p;
  }
  ~MemoryManager() {
    for (int i = 1; i <= _idx; i++) delete[] _buf[i];
  }

 private:
  MemoryManager() { _buf[0] = _init; }
  char _init[INIT * BLOCKSIZE];
  int _size = INIT * BLOCKSIZE;
  int _idx = 0;
  int _pos = 0;
  char* _buf[32] = {};
  void* _ptr = nullptr;
};
template <typename T>
struct BlockAllocater {
  void* operator new(std::size_t count) {
    return MemoryManager<sizeof(T)>::inst()->alloc();
  }
  void operator delete(void* ptr) {
    return MemoryManager<sizeof(T)>::inst()->dealloc(ptr);
  }
};
template <typename T>
struct NullNode {
  static T nullnode;
  static T* null() { return &nullnode; }
  bool isNull() { return this == null(); }
};
template <typename T>
T NullNode<T>::nullnode;
}  // namespace XX
namespace XX {
template <typename... EdgeTs>
class Graph {
 public:
  struct Edge : public EdgeTs... {
    int from, to;
    Edge(int f, int t, EdgeTs... args) : from(f), to(t), EdgeTs(args)... {}
    Edge() {}
  };
  struct Node : public Edge, BlockAllocater<Node> {
    Node* next;
    template <typename... Args>
    Node(Node* nn, Args... args) : next(nn), Edge(args...) {}
  };
  typedef Node* EdgeIdx;

 private:
  std::vector<Node*> _adj;
  int _numVertex;
  void _dealloc(Node* node) {
    if (node) {
      _dealloc(node->next);
      delete node;
    }
  }

 public:
  Graph(int v = 0) : _adj(v) {}
  int size() { return _adj.size(); }
  void resize(int size) { _adj.resize(size); }
  EdgeIdx add(int from, int to, EdgeTs... args) {
    return _adj[from] = new Node{_adj[from], from, to, args...};
  }
  Node& operator[](EdgeIdx idx) { return idx->e; }
  struct Enumerator {
    struct It {
      Node* ptr;
      Node& operator*() { return *ptr; }
      void operator++() { ptr = ptr->next; }
      bool operator!=(const It& other) { return ptr != other.ptr; }
    } b, e;
    It begin() { return b; }
    It end() { return e; }
  };
  struct AllEnumerator {
    struct It {
      Node* ptr;
      int v;
      Graph& g;
      Node& operator*() { return *ptr; }
      void operator++() {
        ptr = ptr->next;
        while (!ptr && ++v < g.size()) ptr = g._adj[v];
      }
      bool operator!=(const It& other) { return ptr != other.ptr; }
    };
    Graph& g;
    It begin() {
      for (int i = 0; i < g.size(); i++)
        if (g._adj[i]) return {g._adj[i], i, g};
      return end();
    }
    It end() { return {nullptr, 0, g}; }
  };
  Enumerator adj(int v) { return {_adj[v], nullptr}; }
  Enumerator adj(EdgeIdx idx) { return {idx, nullptr}; }
  AllEnumerator edges() { return {*this}; }
  Enumerator operator[](int idx) { return adj(idx); }
};
}  // namespace XX
template <typename T>
struct ScanfSpecifier {};
template <>
struct ScanfSpecifier<int> {
  static constexpr const char* value = "%d";
};
template <>
struct ScanfSpecifier<double> {
  static constexpr const char* value = "%lf";
};
template <>
struct ScanfSpecifier<float> {
  static constexpr const char* value = "%f";
};
template <>
struct ScanfSpecifier<char> {
  static constexpr const char* value = "%c";
};
template <>
struct ScanfSpecifier<const char*> {
  static constexpr const char* value = "%s";
};
template <>
struct ScanfSpecifier<unsigned long> {
  static constexpr const char* value = "%lu";
};
template <>
struct ScanfSpecifier<char*> {
  static constexpr const char* value = "%s";
};
template <>
struct ScanfSpecifier<unsigned int> {
  static constexpr const char* value = "%u";
};
template <>
struct ScanfSpecifier<long long int> {
  static constexpr const char* value = "%lld";
};
template <typename T>
int RD(T& arg) {
  return std::scanf(ScanfSpecifier<T>::value, &arg);
}
template <int S>
int RD(char (&arg)[S]) {
  return std::scanf("%s", arg);
}
template <>
int RD<char*>(char*& arg) {
  return std::scanf("%s", arg);
}
template <>
int RD<char>(char& arg) {
  return std::scanf(" %c", &arg);
}
template <typename T, typename... Args>
int RD(T& arg1, Args&... args) {
  return RD(arg1) + RD(args...);
}
template <typename T>
T RD() {
  T ret;
  RD(ret);
  return ret;
}
template <typename It>
void RDV(It begin, It end) {
  while (begin != end) RD(*begin++);
}
template <typename C>
void RDV(C& c) {
  RDV(std::begin(c), std::end(c));
}
template <typename... Args>
void WT(Args... args) {
  int alc = 0;
  int dummy[] = {((alc++ ? std::printf(" ") : 0),
                  std::printf(ScanfSpecifier<Args>::value, args), 0)...};
}
template <typename... Args>
void WTL(Args... args) {
  WT(args...);
  std::printf("\n");
}
template <typename It>
void WTV(It begin, It end) {
  int alc = 0;
  while (begin != end) (alc++ ? std::printf(" ") : 0), WT(*begin++);
}
template <typename C>
void WTV(const C& c) {
  WTV(std::begin(c), std::end(c));
}
template <typename It>
void WTVL(It begin, It end) {
  WTV(begin, end);
  std::printf("\n");
}
template <typename C>
void WTVL(const C& c) {
  WTVL(std::begin(c), std::end(c));
}
namespace XX {
template <template <typename> class Compare, typename T>
inline T& UP(T& x, const T& y) {
  if (Compare<T>()(y, x)) x = y;
  return x;
}
template <typename Compare, typename T>
inline T& UP(T& x, const T& y, Compare comp) {
  if (comp(y, x)) x = y;
  return x;
}
template <typename T>
inline T& GT(T& x, const T& y) {
  return UP<std::greater>(x, y);
}
template <typename T>
inline T& LS(T& x, const T& y) {
  return UP<std::less>(x, y);
}
template <typename T>
struct Mapper {
  int operator[](const T& v) {
    int& ret = table[v];
    if (!ret) rtable[ret = table.size()] = v;
    return ret - 1;
  }
  template <typename... Args>
  int operator()(Args... args) {
    return (*this)[T(args...)];
  }
  T rev(int idx) { return rtable[idx + 1]; }
  std::map<T, int> table;
  std::map<int, T> rtable;
};
template <typename T, int S>
struct ReferenceArray {
  struct It {
    typename std::array<T*, S>::iterator it;
    T& operator*() { return **it; }
    void operator++() { it++; }
    bool operator!=(const It& other) { return it != other.it; }
  };
  int size() const { return _ptr.size(); }
  It begin() const { return {_ptr.begin()}; }
  It end() const { return {_ptr.end()}; }
  T& operator[](int idx) const { return *_ptr[idx]; }
  mutable std::array<T*, S> _ptr;
};
template <typename T, typename... Args>
ReferenceArray<T, sizeof...(Args) + 1> MAKEV(T& arg1, Args&... args) {
  return {&arg1, &args...};
}
struct Range {
  struct It {
    int num, step;
    int operator*() { return num; }
    void operator++() { num += step; }
    bool operator!=(const It& other) { return num != other.num; }
  };
  Range(int ee) : b(0), e(ee) {}
  Range(int bb, int ee) : b(bb), e(ee) {}
  It begin() { return {b, (b < e ? 1 : -1)}; }
  It end() { return {e, 0}; }
  int b, e;
};
}  // namespace XX
using XX::Graph;
template <typename T>
T& UMAX(T& x, T y) {
  return XX::UP<std::greater>(x, y);
}
template <typename T>
T& UMIN(T& x, T y) {
  return XX::UP<std::less>(x, y);
}
using XX::UP;
using RG = XX::Range;
using XX::MAKEV;
using XX::Mapper;
using namespace std;
int N, Q;
Graph<> tree;
vector<int> qs[500000];
int ans[500000];
int amt[500000];
int dfs(int n) {
  amt[n] = 1;
  for (auto& e : tree[n]) amt[n] += dfs(e.to);
  return amt[n];
}
set<pair<int, int>> table;
void dfs2(int u) {
  for (auto& q : qs[u]) table.emplace(amt[u], q);
  int sum = 0;
  int mx = 0;
  for (auto& e : tree[u]) {
    sum += amt[e.to];
    UMAX(mx, amt[e.to]);
  }
  auto l = table.lower_bound({mx * 2, 0});
  auto r = table.lower_bound({sum * 2 + 2 + 1, 0});
  for (auto it = l; it != r; it++) ans[it->second] = u + 1;
  table.erase(l, r);
  for (auto& e : tree[u]) dfs2(e.to);
}
int main() {
  RD(N, Q);
  tree.resize(N);
  for (int i = 1; i < N; i++) {
    int p;
    RD(p);
    tree.add(p - 1, i);
  }
  for (int i = 0; i < Q; i++) {
    int v;
    RD(v);
    qs[v - 1].push_back(i);
  }
  dfs(0);
  dfs2(0);
  for (int i = 0; i < Q; i++) WTL(ans[i]);
}

```