#include <vector>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, m, a[100009], cnt; vector<int> g[100009];
int rec(int pos, int pre) {
	int e = 0;
	for (int i : g[pos]) {
		if (i == pre) continue;
		e = max(e, rec(i, pos));
	}
	if (e == m - 1) {
		if(pre != 0) cnt++;
		return 0;
	}
	return e + 1;
}
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]), a[i]--;
	for (int i = 1; i < n; i++) g[a[i]].push_back(i);
	for (int i : g[0]) rec(i, 0);
	printf("%d\n", cnt + (a[0] != 0 ? 1 : 0));
	return 0;
}