#include <bits/stdc++.h>
using namespace std;
int n, tar, root, a;
vector<int> adj[51];

int dfs(int here){
    int ret = 0, child = 0;
    for(int there : adj[here]){
        if(there == tar) continue;
        ret += dfs(there);
        child++;
    }
    if(child = 0) return 1;
    return ret;
}

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a == -1) root = i;
        else adj[i].push_back(a);
    }
    cin >> tar;
    
    cout << dfs(root) << '\n';
}