#include <bits/stdc++.h>
using namespace std;
int n, k, ans;
const int N = 200000;
queue <int> Q;
int ai[N], cc[N], ext[N];
int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; ++ i) cin >> ai[i];
    if (ai[1] != 1) ai[1] = 1, ans ++;
    for (int i = 1; i <= n; ++ i) cc[ai[i]] ++, ext[i] = k;
    for (int i = 1; i <= n; ++ i)
        if (!cc[i]) Q.push(i);
    while (!Q.empty())
    {
        int i = Q.front(); Q.pop();
        if (ai[i] != 1? ext[i] <= 1: ext[i] <= 0) ext[i] = k + 1, ans ++;
        cc[ai[i]] --, ext[ai[i]] = min(ext[i] - 1, ext[ai[i]]);
        if (cc[ai[i]] == 0) Q.push(ai[i]);
    }
    cout << ans << endl;
}
