#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 3e5 + 5;
vector <int> g[MAXN];
int h[MAXN];
void dfs(int v){
    for (auto to: g[v]){
        h[to] = h[v] + 1;
        dfs(to);
    }
}
signed main(){
    int n, q;
    cin >> n >> q;
    for (int i = 2; i <= n; i++){
        int p;
        cin >> p;
        g[p].push_back(i);
    }
    vector <int> s(n + 1);
    for (int i = 1; i <= n; i++){
        cin >> s[i];
    }
    h[1] = 0;
    dfs(1);
    while (q--){
        int v;
        cin >> v;
        cout << h[v] << '\n';
    }
}
