#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 3e5 + 5;
vector <int> g[MAXN];
vector <int> gg[MAXN];
int s[MAXN];
int pos[MAXN];
int ans[MAXN];
int p[MAXN];
void dfs(int v){
    for (auto to: g[v]){
        if (v == s[1]){
            p[to] = to;
        }
        else{
            p[to] = p[v];
        }
        dfs(to);
    }
}
signed main(){
    int n, q;
    cin >> n >> q;
    for (int i = 2; i <= n; i++){
        int p;
        cin >> p;
        gg[p].push_back(i);
    }
    for (int i = 1; i <= n; i++){
        cin >> s[i];
    }
    for (int i = 1; i <= n; i++){
        for (auto v: gg[i]){
            g[s[i]].push_back(s[v]);
        }
    }
    dfs(s[1]);
    int root = s[1];
    set <pair <int, int>> dst;
    vector <int> ct(n + 1, 0);
    for (int i = 1; i <= n; i++){
        if (p[i] == i){
            dst.insert({0, i});
        }
    }
    set <int> st;
    for (auto to: g[root]){
        st.insert(to);
    }
    int cnt = 0;
    while (cnt != n - 1){
        cnt++;
        auto x = *(st.rbegin());
        int pp = p[x];
        int nw = ct[pp];
        dst.erase({nw, pp});
        ct[pp]++;
        nw = ct[pp];
        dst.insert({nw, pp});
        auto ss = *(dst.rbegin());
        if (ss.second != p[x]){
            ans[x] = ss.first;
        }
        else{
            auto ss = *(--dst.rbegin());
            ans[x] = ss.first;
        }
        pos[x] = cnt;
        st.erase(x);
        for (auto to: g[x]){
            st.insert(to);
        }
        root = x;
    }
    while (q--){
        int v;
        cin >> v;
        v = s[v];
        cout << pos[v] - ans[v] << '\n';
    }
}
