Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K = map(int, input().split())


A_list = list(map(int, input().split()))
A_list = np.array(A_list) - 1
#A_list = [A - 1 for A in A_list]

path = [0]
town = 0
k = K
j = 0
while k > 0:
  town = A_list[town]
                     
  if town in path:
    #print("town is {}".format(town))
    #print("path is {}".format(path))
    first_visit = path.index(town)
    loop_size = j - first_visit + 1
    #print("loop_size is {}".format(loop_size))
    #print("k is {}".format(k))
    k = (k-1) % loop_size 
    #print("k is now {}".format(k))
    town = path[first_visit + k]
    break
    
  path.append(town)
    
  k = k - 1
  j = j + 1

print(town+1)

Fixed submission:
N, K = map(int, input().split())

A_list = list(map(int, input().split()))
A_list = [A - 1 for A in A_list]

path = [0]
town = 0
k = K
j = 0

while k > 0:
  town = A_list[town]
   
  if k % 10000 == 0:
    if town in path:
      #print("town is {}".format(town))
      #print("path is {}".format(path))
      first_visit = path.index(town)
      loop_size = j - first_visit + 1
      #print("loop_size is {}".format(loop_size))
      #print("k is {}".format(k))
      k = (k-1) % loop_size 
      #print("k is now {}".format(k))
      town = path[first_visit + k]
      break
    
  path.append(town)
    
  k = k - 1
  j = j + 1

print(town+1)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

A_list = list(map(int, input().split()))
A_list = [A - 1 for A in A_list]

path = [0]
town = 0
k = K
j = 0
while k > 0:
  town = A_list[town]
                     
  if town in path:
    #print("town is {}".format(town))
    #print("path is {}".format(path))
    first_visit = path.index(town)
    loop_size = j - first_visit + 1
    #print("loop_size is {}".format(loop_size))
    #print("k is {}".format(k))
    k = (k-1) % loop_size 
    #print("k is now {}".format(k))
    town = path[first_visit + k]
    break
    
  path.append(town)
    
  k = k - 1
  j = j + 1

print(town+1)

Fixed submission:
N, K = map(int, input().split())

A_list = list(map(int, input().split()))
A_list = [A - 1 for A in A_list]

path = [0]
town = 0
k = K
j = 0

while k > 0:
  town = A_list[town]
   
  if k % 10000 == 0:
    if town in path:
      #print("town is {}".format(town))
      #print("path is {}".format(path))
      first_visit = path.index(town)
      loop_size = j - first_visit + 1
      #print("loop_size is {}".format(loop_size))
      #print("k is {}".format(k))
      k = (k-1) % loop_size 
      #print("k is now {}".format(k))
      town = path[first_visit + k]
      break
    
  path.append(town)
    
  k = k - 1
  j = j + 1

print(town+1)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

A_list = list(map(int, input().split()))
A_list = [A - 1 for A in A_list]

path = [0]
town = 0
k = K
j = 0
while k > 0:
  town = A_list[town]
                     
  if town in path:
    #print("town is {}".format(town))
    #print("path is {}".format(path))
    first_visit = path.index(town)
    loop_size = j - first_visit + 1
    #print("loop_size is {}".format(loop_size))
    #print("k is {}".format(k))
    k = (k-1) % loop_size 
    #print("k is now {}".format(k))
    path = []
    continue
    
  path.append(town)
    
  k = k - 1
  j = j + 1

print(town+1)

Fixed submission:
N, K = map(int, input().split())

A_list = list(map(int, input().split()))
A_list = [A - 1 for A in A_list]

path = [0]
town = 0
k = K
j = 0

while k > 0:
  town = A_list[town]
   
  if k % 10000 == 0:
    if town in path:
      #print("town is {}".format(town))
      #print("path is {}".format(path))
      first_visit = path.index(town)
      loop_size = j - first_visit + 1
      #print("loop_size is {}".format(loop_size))
      #print("k is {}".format(k))
      k = (k-1) % loop_size 
      #print("k is now {}".format(k))
      town = path[first_visit + k]
      break
    
  path.append(town)
    
  k = k - 1
  j = j + 1

print(town+1)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

A_list = list(map(int, input().split()))
A_list = [A - 1 for A in A_list]

path = [0]
town = 0
k = K
j = 0
while k > 0:
  town = A_list[town]
                     
  if town in path:
    #print("town is {}".format(town))
    #print("path is {}".format(path))
    first_visit = path.index(town)
    loop_size = j - first_visit + 1
    #print("loop_size is {}".format(loop_size))
    #print("k is {}".format(k))
    k = (k-1) % loop_size 
    #print("k is now {}".format(k))
    path = []
    continue
    
  path.append(town)
    
  k = k - 1
  j = j + 1

print(town+1)

Fixed submission:
N, K = map(int, input().split())

A_list = list(map(int, input().split()))
A_list = [A - 1 for A in A_list]

path = [0]
town = 0
k = K
j = 0

while k > 0:
  town = A_list[town]
   
  if k % 10000 == 0:
    if town in path:
      #print("town is {}".format(town))
      #print("path is {}".format(path))
      first_visit = path.index(town)
      loop_size = j - first_visit + 1
      #print("loop_size is {}".format(loop_size))
      #print("k is {}".format(k))
      k = (k-1) % loop_size 
      #print("k is now {}".format(k))
      town = path[first_visit + k]
      break
    
  path.append(town)
    
  k = k - 1
  j = j + 1

print(town+1)