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 n=as[0]==0?0:1;
    int dfs(int v, int k)
    {
        int m=K-1;
        foreach(i;g[v]) m=min(m,dfs(i,k+1));
        if(m==0 && v!=0)
        {
            if(as[v]!=0) ++n;
            m=K;
        }
        return m-1;
    }
    dfs(0,0);
    return n;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }