#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <set>
#include <random>
using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) static_cast<lng>(x.size())

using lng = long long;

vector<vector<int>> g, dist;
vector<set<pair<int, int>, greater<pair<int, int>>>*> gp;
vector<int> cur_comp, color;

void dfs(int v, int c) {
	color[v] = c;
	for (int u : g[v]) {
		dfs(u, c);
	}
}

void check(int c) {
	gp.assign(sz(g), nullptr);
	int timer = 0, cur_boss = 0;
	for (int i = 0; i < sz(g); i++) {
		gp[i] = new set<pair<int, int>, greater<pair<int, int>>>{};
		for (int u : g[i]) {
			gp[i]->emplace(cur_comp[u], u);
		}
	}
	while (timer < sz(g)) {
		dist[c][cur_boss] = timer++;
		if (!gp[cur_boss]->empty()) {
			int new_boss = gp[cur_boss]->begin()->second;
			gp[cur_boss]->erase(gp[cur_boss]->begin());
			if (gp[new_boss]->size() < gp[cur_boss]->size()) {
				swap(gp[cur_boss], gp[new_boss]);
			}
			for (auto it = gp[cur_boss]->begin(); it != gp[cur_boss]->end(); it++) {
				gp[new_boss]->insert(*it);
			}
			cur_boss = new_boss;
		}
	}
}

void solve() {
	int n, q; cin >> n >> q;
	g.assign(n, vector<int>(0));
	for (int i = 1; i < n; i++) {
		int p; cin >> p;
		p--;
		g[p].push_back(i);
	}
	dist.assign(1, vector<int>(n, 1e6));
	cur_comp.resize(n);
	check(0); 
	for (int u : g[0]) {
		dfs(u, u);
	}
	vector<int> order(n);
	for (int i = 0; i < n; i++) {
		order[dist[0][i]] = i;
	}
	vector<int> cnt(n, 0);
	multiset<pair<int, int>, greater<pair<int, int>>> ms;
	for (int i = 0; i < n; i++) {
		ms.emplace(0, i);
	}
	vector<int> ans(n, 0);
	for (int i = 1; i < n; i++) {
		int v = order[i];
		auto p = *ms.begin();
		if (p.second == color[v]) {
			p = *(++ms.begin());
		}
		ans[v] = i - p.first;
		ms.erase(ms.find({ cnt[color[v]], color[v]}));
		cnt[color[v]]++;
		ms.emplace(cnt[color[v]], color[v]);
	}
	for (int t = 0; t < q; t++) {
		int v; cin >> v; --v;
		cout << ans[v] << ' ';
	}
}

int main() { 
	cin.tie(nullptr)->sync_with_stdio(false);
	int t = 1;
	while (t--) {
		solve();
	}
	return 0;
}