#include <bits/stdc++.h>
#define int long long

using namespace std;

vector <int> p, h;

void go_up(int v) {
    if (h[p[v]] == -1) {
        go_up(p[v]);
    }
    h[v] = h[p[v]] + 1;
}

signed main() {
    int n, q;
    cin >> n >> q;
    p.resize(n);
    vector <int> s(n);
    for (int i = 1; i < n; ++i) {
        cin >> p[i];
        p[i]--;
    }
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    h.resize(n, -1);
    h[0] = 0;
    for (int i = 0; i < n; ++i) {
        if (h[i] == -1) go_up(i);
    }
    while (q--) {
        int v;
        cin >> v;
        cout << h[v] << endl;
    }
    return 0;
}
