#include <bits/stdc++.h>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
#define INF (1 << 30)
using namespace std;

int N, K, A;
vector<int> R, E[100000];
bool ans[100000];

int dfs(int v) {
  int depth = INF;
  for(int u : E[v]) depth = min(depth, dfs(u));
  if(depth == INF) depth = 0;
  if(depth < K) ans[v] = true;
  return depth + 1;
}

int main(void) {
  cin >> N >> K;
  REP(i, 0, N) {
    cin >> A;
    if(A >= 1) E[A - 1].push_back(i);
    else R.push_back(i);
  }

  REP(i, 0, N) ans[i] = false;
  REP(i, 0, R.size()) ans[R[i]] = true, dfs(R[i]);

  int cnt = 0;
  REP(i, 0, N) if(ans[i]) cnt++;
  cout << cnt << endl;
}