#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

//#pragma GCC Optimize("O3")
//#pragma GCC Optimize("unroll-loops")
//#pragma GCC target("avx,avx2,bmi")

//using namespace __gnu_pbds;
using namespace std;

//template <class T> using ordered_set = tree<T, null_type, less<T> ,rb_tree_tag,tree_order_statistics_node_update>;
//struct h{
//    size_t operator ()(const pair<int,int>& a) const{
//        return ((size_t)a.first << 32) + a.second;
//    }
//};
void solve();

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin>>t;
    while (t--) {
        solve();
    }
    return 0;
}

#define int long long
#define endl '\n'
const int INF = 2e18;
const int MAXN = 3e5+1;
const int MOD = 1e9 + 7;

vector<int> gr[MAXN];
int s[MAXN];

bool cmp(int v, int u) {
    return s[v] > s[u];
}
int sz[MAXN];
int pref[MAXN];
int sum[MAXN];
int posi[MAXN];
int h[MAXN];
void dfs(int v, int pos) {
    sz[v]=1;
    posi[v]=pos;
    if (v==0) {
        int p = 1;
        for (int i : gr[v]) {
            h[i]=h[v]+1;
            dfs(i, p++);
            sz[v] += sz[i];
        }
        for (int i = 0; i < gr[v].size(); i++) {
            sum[i+1]=sum[i]+sz[gr[v][i]];
            pref[i + 1] = max(pref[i], sz[gr[v][i]]);
        }
    } else {
        for (int i : gr[v]) {
            h[i]=h[v]+1;
            dfs(i, pos);
            sz[v] += sz[i];
        }
    }
}

void solve() {
    int n,q;
    cin >> n >> q;
    vector<int> par(n,-1);
    for (int i = 1; i < n; i++) {
        int p;
        cin >> p;
        par[i]=p-1;
        gr[p-1].push_back(i);
    }
    for (int i = 0; i < n; i++) {
        sort(gr[i].begin(), gr[i].end(),cmp);
    }
    int mmn=-INF;
    if (gr[0].size() > 1) {
        mmn = s[gr[0][1]];
    }
    dfs(0,-1);
    while (q--) {
        int v;
        cin >> v;
        v--;
        if (v==0) {
            cout << 0 << ' ';
            continue;
        }
        if (par[v]==0) {
            cout << sum[posi[v]-1] - pref[posi[v]-1] + 1 << ' ';
        } else {
            if (posi[v]==1) {
                if (h[v]==2) {
                    if (mmn < s[v]) {
                        cout << 1 << ' ';
                    } else {
                        cout << 2 << ' ';
                    }
                } else {
                    cout << h[v]-1 << ' ';
                }
                continue;
            } else {
                cout << sum[posi[v]-1] - pref[posi[v]-1] + h[v] << ' ';
            }
        }
    }
}
