import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;
		a[] -= 1;
		auto g = new int [] [n];
		foreach (i; 0..n)
		{
			g[a[i]] ~= i;
		}
		debug {writeln (g);}

		auto d = new int [n];

		int res = (a[0] != 0);

		void recur (int v)
		{
			d[v] = 0;
			foreach (u; g[v])
			{
				if (u != 0)
				{
					recur (u);
					d[v] = max (d[v], d[u] + 1);
				}
			}
			if (v != 0 && d[v] % k == k - 1 && a[v] != 0)
			{
				assert (d[v] == k - 1);
				a[v] = 0;
				res += 1;
				d[v] = -1;
			}
		}

		recur (0);
		debug {writeln (d);}
		writeln (res);
	}
}
