
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define ve vector
#define pb push_back
#define all(a) a.begin(), a.end()
#define first f
#define second s
using ld = long double;
#define int ll
mt19937 rnd(321932);

template<class A>
istream &operator>>(istream &in, ve<A> &a) {
    for (auto &x: a)
        in >> x;
    return in;
}

template<class A>
ostream &operator<<(ostream &out, ve<A> a) {
    for (auto &x: a)
        out << x << ' ';
    return out << '\n';
}

void sol() {
    int n, m;
    cin >> n >> m;
    ve<int> x(m);
    cin >> x;
    reverse(all(x));
    // dp[j] --- max res if we used j bad x
    ve<ve<int>> dp(m + 1, ve<int>(m + 1, -1e18));
    dp[0][0] = 0;
    for (int cnt = 1; cnt <= m; ++cnt) {
        cout << (cnt+1)/2 << ' ' << min(cnt, (cnt+n)/2) << '\n';
        for (int i = (cnt+1)/2; cnt + n >= 2 * i && i <= cnt; ++i) {
            dp[i][cnt] = max(dp[i][cnt-1], dp[i-1][cnt-1] + x[cnt-1]);
        }
    }
    int sum = 0;
    for (auto &c : x)
        sum += c;
    int mx = -1e18;
    for (int i = 0; i <= m; ++i)
        mx = max(mx, dp[i][m]);
    cout << 2 * mx - sum << '\n';
}
ve<ve<int>> g;
ve<int> h;
void dfs(int v) {
    for (auto &u : g[v]) {
        h[u] = h[v] + 1;
        dfs(u);
    }
}
int32_t main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, q;
    cin >> n >> q;
    ve<int> p(n, -1);
    g.resize(n);
    h.assign(n, 0);
    int x = 0;
    for (int i = 1; i < n; ++i) {
        cin >> p[i];
        p[i]--;
        g[p[i]].pb(i);
    }
    dfs(0);
    ve<int> c(n);
    cin >> c;
    while (q--) {
        int v;
        cin >> v;
        v--;
        cout << h[v] << '\n';
    }
}
