#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve()
{
	int n,q;
	cin>>n>>q;
	vector<vector<int>> v;
	int dep[n+1]={};
	for (int i=2;i<=n;i++)
	{
		int p;
		cin>>p;
		if (p==1)
			v.push_back({p});
		else
			v.back().push_back(p);
		dep[i]=dep[p]+1;
	}
	while (q--)
	{
		int x;
		cin>>x;
		cout<<dep[x]<<endl;
	}
	return;
	int a[n+1],m=v.size();
	for (int i=1;i<=n;i++)
		cin>>a[i];
	pair<int,int> id[n+1];
	vector<vector<pair<int,int>>> mn;
	for (int i=0;i<m;i++)
	{
		vector<pair<int,int>> v1={{n+1,-1}};
		int o=0;
		for (int j=0;j<v[i].size();j++)
		{
			id[v[i][j]]={i,j};
			if (a[v[i][j]]<a[v[i][o]])
				o=j;
			v1.push_back({a[v[i][o]],o});
		}
		mn.push_back(v1);
	}
	// int poi
}

signed main()
{
	int t=1;
	while (t--)
		solve();
	
	return 0;
}