#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP2(i,m,n) for (int i=m;i<(n);i++)
typedef long long ll;

int N, K;
int A[101010];
vector<int> edges[101010];
int indeg[101010];
bool ok[101010];


int dfs(int n) {
    if (edges[n].size() == 0) {
        ok[n] = true;
        return 1;
    }

    if (indeg[n] == 0)
        ok[n] = true;

    int ret = 1 << 29;
    for (auto m: edges[n])
        ret = min(ret, dfs(m));

    if (ret < K)
        ok[n] = true;

    return ret + 1;
}


int main() {
    memset(ok, 0, sizeof(ok));
    memset(indeg, 0, sizeof(indeg));

    cin >> N >> K;
    REP(i, N) {
        int a; cin >> a;
        A[i] = a - 1;
    }

    REP(i, N) if (A[i] >= 0) {
        edges[A[i]].push_back(i);
        indeg[i] += 1;
    }

    REP(i, N) if (indeg[i] == 0) dfs(i);

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

    return 0;
}