#include <bits/stdc++.h>
#define N 100010
#define INF (1e9)
using namespace std;

int n,K;
int par[N];
vector<int> G[N];

int bfs(){
  queue<int> Q;
  vector<int> D(N,INF);
  
  for(int i=1;i<=n;i++) if(par[i] == 0) Q.push(i),D[i] = 1;
  
  int res = 0;
  while(!Q.empty()){
    int pos = Q.front();Q.pop();
    int cost = D[pos];
    int to = G[pos].empty()? -1:G[pos][0];
    res += to == 0 || cost <= K;
    if(to >0 && D[to] == INF) Q.push(to),D[to] = cost+1;
  }
  return res;
}


int main(){
  cin>>n>>K;

  for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    G[i].push_back(a);
    par[a] = 1; 
  }
  cout<<bfs()<<endl;
  
  return 0;
}