import sys

sys.setrecursionlimit(10**7)



def solve(s):

    global ans

    h=0

    for i in ch[s]:

        h=max(h,solve(i)+1)

    if h==k-1 and a[s]!=0:

        ans+=1

        a[s]=0

        return -1

    return h



n,k=list(map(int,input().split()))

a=[int(x)-1 for x in input().split()]

ans=0

ch=[[] for _ in range(n)]



if a[0]!=0:

    a[0]=0

    ans+=1



for i in range(1,n):

    ch[a[i]].append(i)



solve(0)

print(ans)
import sys

sys.setrecursionlimit(10 ** 6)



def dfs(now, par):

    h = 0

    global ans

    for child in g[now]:

        if child == par: continue

        h = max(h, dfs(child, now))

    if h == k - 1 and par != 0:

        ans += 1

        h = -1

    return h + 1



n, k = list(map(int, input().split()))

a = list(map(int, input().split()))

g = [[] for _ in range(n)]

ans = 0

if a[0] != 1:

    a[0] = 1

    ans += 1

for i in range(n):

    g[a[i] - 1].append(i)

dfs(0, 0)

print(ans)

import sys

sys.setrecursionlimit(10**7)


def solve(s):
    global ans
    h = 0
    for i in ch[s]:
        h = max(h, solve(i) + 1)
    if h == k - 1 and a[s] != 0:
        ans += 1
        a[s] = 0
        return -1
    return h


n, k = list(map(int, input().split()))
a = [int(x) - 1 for x in input().split()]
ans = 0
ch = [[] for _ in range(n)]
if a[0] != 0:
    a[0] = 0
    ans += 1
for i in range(1, n):
    ch[a[i]].append(i)
solve(0)
print(ans)

import sys

sys.setrecursionlimit(10**6)


def dfs(now, par):
    h = 0
    global ans
    for child in g[now]:
        if child == par:
            continue
        h = max(h, dfs(child, now))
    if h == k - 1 and par != 0:
        ans += 1
        h = -1
    return h + 1


n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
g = [[] for _ in range(n)]
ans = 0
if a[0] != 1:
    a[0] = 1
    ans += 1
for i in range(n):
    g[a[i] - 1].append(i)
dfs(0, 0)
print(ans)

-sys.setrecursionlimit(10**7) +sys.setrecursionlimit(10**6) -def solve(s): +def dfs(now, par): +    h = 0 -    h = 0 -    for i in ch[s]: -        h = max(h, solve(i) + 1) -    if h == k - 1 and a[s] != 0: +    for child in g[now]: +        if child == par: +            continue +        h = max(h, dfs(child, now)) +    if h == k - 1 and par != 0: -        a[s] = 0 -        return -1 -    return h +        h = -1 +    return h + 1 -a = [int(x) - 1 for x in input().split()] +a = list(map(int, input().split())) +g = [[] for _ in range(n)] -ch = [[] for _ in range(n)] -if a[0] != 0: -    a[0] = 0 +if a[0] != 1: +    a[0] = 1 -for i in range(1, n): -    ch[a[i]].append(i) -solve(0) +for i in range(n): +    g[a[i] - 1].append(i) +dfs(0, 0)