#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define int long long

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
const int INF = 1e18;
const int MOD = 1e9 + 7;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

vector<vector<int>> g;
vector<bool> vis;
vector<int> ans;
vector<int> s;

void dfs(int v, int tnow = 0) {
    ans[v] = tnow;
    vis[v] = true;
    pair<int, int> now = {-1, -1};
    for (int u : g[v]) {
        if (vis[u]) continue;
        now = max(now, {s[u], u});
    }
    if (now.second == -1) return;
    int newv = now.second;
    for (int u : g[v]) {
        if (vis[u] || u == newv) continue;
        g[newv].push_back(u);
    }
    dfs(newv, tnow + 1);
}

void solve() {
    int n, q;
    cin >> n >> q;
    g.resize(n);
    vector<int> par(n);
    for (int i = 1; i < n; ++i) {
        int v;
        cin >> v;
        --v;
        g[i].push_back(v);
        g[v].push_back(i);
        par[i] = v;
    }
    s.resize(n);
    for (int i = 0; i < n; ++i) cin >> s[i];
    vis.resize(n);
    ans.resize(n);
    dfs(0);
    while (q--) {
        int v;
        cin >> v;
        --v;
        int ansik = ans[v];
        bool ok = true;
        while (v) {
            if (ans[par[v]] + 1 != ans[v]) {
                ok = false;
                break;
            }
        }
        if (!ok) --ansik;
        cout << ansik << " ";
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}
