#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define yes() cout << "YES\n"
#define no() cout << "NO\n"
using ll = long long;
using ld = long double;
using namespace std;
using namespace __gnu_pbds;

template<typename K>
using oset = tree<K, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

vector<set<int>> g;
vector<int> sv;
vector<int> h;

void dfs(int v, int p, int d) {
    h[v] = d;

    for (auto& u : g[v]) {
        if (u != p) {
            dfs(u, v, d + 1);
        }
    }
}

void solve() {
    int n, q;
    cin >> n >> q;

    g.resize(n);
    sv.resize(n);

    for (int i = 2; i <= n; i++) {
        int u;
        cin >> u;

        u--;

        g[u].insert(i - 1);
//        g[i - 1].insert(u);
    }

    for (int& i : sv) cin >> i;

    dfs(0, 0, 0);
    while (q--) {
        int v;
        cin >> v;

        v--;
        cout << h[v] << " ";
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    // cin >> t;

    while (t--) {
        solve();
    }
}