output_description: Print the integer representing the town the king will be in if he starts at
  Town 1 and uses a teleporter exactly K times from there.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N K
      A_1 A_2 \dots A_N
attempt: N, K = map(int, input().split())
  a = list(map(int, input().split()))
  list_a = []
  list_b = []
  list_a.append(1)
  count_a = 1
  count_b = 0
  for i in range(1, K + 1):
      if i == 1:
          k = i
      if a[k - 1] in list_b:
          break
      elif a[k - 1] in list_a:
          list_b.append(a[k - 1])
          count_b += 1
          if a[k - 1] == 1:
              handan = True
      if a[k - 1] not in list_a:
          list_a.append(a[k - 1])
          count_a += 1
      k = a[k - 1]
  # print(list_a,list_b,count_a,count_b)
  if count_b != 0:
      num_k = K - (count_a - count_b)
      num_k = num_k % count_b
      if handan == True and list_b[0] != 1:
          # list_b.remove(1)
          list_b.insert(0, 1)
      print(list_b[num_k])
  elif count_b == 0:
      print(list_a[count_a - 1])
  
problem_description: Statement
  
  The Kingdom of Takahashi has N towns, numbered 1 through N.
  
  There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
  N) sends you to Town A_i.
  
  Takahashi, the king, loves the positive integer K. The selfish king wonders
  what town he will be in if he starts at Town 1 and uses a teleporter exactly K
  times from there.
  
  Help the king by writing a program that answers this question.
samples: [{"input": "4 5\n    3 2 4 1", "output": "4\n    \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n    6 5 2 5 3 2", "output": "2"}]