import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
 
auto solve(string s_)
{
    auto NK = s_.split.map!(to!int)();
    immutable N=NK[0], K=NK[1];
    auto as = readln.split.map!(x=>x.to!int()-1).array();
    auto g = new int[][N];
    foreach(int i,v;as) if(i!=0) g[v]~=i;
    int m=0;
    auto d = new int[N];
    void dfs(int v, int k)
    {
        ++d[k]; m=max(m,k);
        foreach(i;g[v]) dfs(i,k+1);
    }
    dfs(0,0);
    int n=as[0]==0?0:1;
    for(int i=m; i>K; i-=K) n+=d[i-(K-1)];
    return n;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }