#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <climits>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <string>
#include <queue>
#include <random>

#define int long long

#pragma GCC optimize("03,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using ll = long long;
using ld = long double;
using namespace std;

const ll INF = 1e18;

vector<vector<int>> g;
vector<int> d;


void dfs(int v, int dist){
    d[v] = dist;
    for (auto &to : g[v]){
        dfs(to, dist + 1);
    }
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    d.resize(n);
    g.resize(n);
    for (int i = 1; i < n; i++){
        int c;
        cin >> c;
        c--;
        g[c].push_back(i);
    }
    dfs(0, 0);
    while (q--){
        int x;
        cin >> x;
        x--;
        cout << d[x] << " ";
    }
}


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}