#include <bits/stdc++.h>

using ll = long long;
using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    int k = -1;
    for (int i = 2; i <= n; ++i) {
        int p;
        cin >> p;
        if (p == 1 && i != 2) k = i;
    }
    vector<int> s(n + 1);
    for (int i = 1; i <= n; ++i) cin >> s[i];
    vector<int> ans;
    for (int qi = 0; qi < q; ++qi) {
        int v;
        cin >> v;
        if (v == 1) ans.push_back(0);
        else if (k == -1 || v == 2) ans.push_back(v - 1);
        else if (v >= k) ans.push_back(v - k + 1);
        else ans.push_back(v - 1);
    }
    for (auto i : ans) cout << i << " ";
}