output_description: Print the minimum number of the Teleporters whose destinations need to be
  changed in order to satisfy King Snuke's desire.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      N K
      a_1 a_2 ... a_N
attempt: class city:
      def __init__(self, i, ai):
          self.i = i
          self.parent = ai
          self.children = []
          self.done = False
  
      def addchild(self, c):
          self.children.append(c)
  
  
  def recurdone(b, i, k):
  
      if b[i].done:
          return
      b[i].done = True
  
      if k == 0:
          return
      for j in b[i].children:
          recurdone(b, j, k - 1)
  
  
  def recurfix(b, i, k):
      if k == 1:
          b[i].done = True
  
          recurdone(b, i, km - 1)
          b[b[i].parent].children.remove(i)
          if len(b[b[i].parent].children) == 0:
              ends.append(b[i].parent)
          return
      if b[i].done:
          recurdone(b, i, km)
          return
      else:
          b[i].done = True
  
          recurfix(b, b[i].parent, k - 1)
  
  
  line = input().split()
  n = int(line[0])
  global km
  km = int(line[1])
  a = input().split()
  for i in range(n):
      a[i] = int(a[i])
  b = []
  for i in range(n):
      b.append(city(i, a[i] - 1))
  for i in range(n):
      b[b[i].parent].addchild(i)
  changes = 0
  if b[0].parent != 0:
      b[b[0].parent].children.remove(0)
      b[0].parent = 0
      b[0].addchild(0)
      changes = 1
  
  
  recurdone(b, 0, km)
  global ends
  ends = []
  other = []
  for i in range(n):
      if b[i].done:
          pass
      else:
          if len(b[i].children) == 0:
              ends.append(i)
          else:
              other.append(i)
  for city in ends:
      if b[city].done:
          pass
      else:
  
          changes += 1
          recurfix(b, city, km)
  for city in other:
      if b[city].done:
          pass
      else:
  
          changes += 1
          recurdone(b, city.i, km - 1)
  print(changes)
  
problem_description: Statement
  
  There are N towns in Snuke Kingdom, conveniently numbered 1 through N. Town 1
  is the capital.
  
  Each town in the kingdom has a _Teleporter_ , a facility that instantly
  transports a person to another place. The destination of the Teleporter of
  town i is town a_i (1≤a_i≤N). It is guaranteed that **one can get to the
  capital from any town by using the Teleporters some number of times**.
  
  King Snuke loves the integer K. The selfish king wants to change the
  destination of the Teleporters so that the following holds:
  
    * Starting from any town, one will be at the capital after using the Teleporters exactly K times in total.
  
  Find the minimum number of the Teleporters whose destinations need to be
  changed in order to satisfy the king's desire.
samples: [{"input": "3 1\n    2 3 1", "output": "2\n    \n\nChange the destinations of the Teleporters to a = (1,1,1).\n\n* * *"}, {"input": "4 2\n    1 1 2 2", "output": "0\n    \n\nThere is no need to change the destinations of the Teleporters, since the\nking's desire is already satisfied.\n\n* * *"}, {"input": "8 2\n    4 1 2 3 1 2 3 4", "output": "3\n    \n\nFor example, change the destinations of the Teleporters to a =\n(1,1,2,1,1,2,2,4)."}]