#include <bits/stdc++.h>

int n, K, ans, a[112345];
std::vector<int> g[112345];

int dfs(int u) {
	int mx = 0;
	for (int v: g[u]) {
		mx = std::max(mx, dfs(v) + 1);
	}
	if(u != 1 && mx == K - 1) {
		ans += (a[u] != 1);
		mx = -1;
	}
//	printf("dfs(%d) = %d\n", u, mx);
	return mx;
}

int main() {
	scanf("%d%d", &n, &K);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
		if(i > 1) {
			g[a[i]].push_back(i);
		}
	}
	ans = (a[1] != 1);
	dfs(1);
	printf("%d\n", ans);
}