#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, Q, q;
    cin >> n >> Q;
    vector<vector<int>> g(n, vector<int>(0));
    vector<int> p(n, -1);
    vector<int> rp(n, -1);
    for (int i = 0; i < n - 1; i++) {
        cin >> q;
        q--;
        if (q == 0) {
            rp[i + 1] = 0;
        } else {
            rp[i + 1] = rp[i];
        }
        p[i + 1] = q;
        g[q].push_back(i + 1);
    }
    vector<int> res(n, 0);
    int d(0);
    vector<int> s(n), t(n);
    for (int i = 0; i < n; i++) {
        cin >> q;
        q--;
        s[i] = q;
        t[q] = i;
    }
    set<int> st{-s[0]};
    vector<int> u(n, 0);
    vector<int> mx(n, 0), mx2(n, 0);
    for (int i = 0; i < n; i++) {
        d = t[-*(st.begin())];
        st.erase(st.begin());
        //cout << i << " " << d << endl;
        for (auto i : g[d]) {
            st.insert(-s[i]);
        }
        int P(d), mxc(0);
        //cout << "TEST" << endl;
        while (true) {
            int pP(rp[P]);
            //cout << P << " " << pP << endl;
            if (pP == -1) {
                break;
            }
            if (u[P] == mx[pP]) {
                mx[pP]++;
                mxc = max(mxc, mx2[pP]);
            } else if (u[P] == mx2[pP]) {
                mx2[pP]++;
                mxc = max(mxc, mx[pP]);
            } else {
                mxc = max(mxc, mx[pP]);
            }
            u[P]++;
            P = pP;
        }
        //cout << d << " " << i << " " << mxc << endl;
        res[d] = i - mxc;
    }
    for (int i = 0; i < Q; i++) {
        cin >> q;
        q--;
        cout << res[q] << " ";
    }
}
