Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
ls_pass = [0]+list(map(int,input().split()))
a=1
b=0
c=0
d=0
ls_past=[1]
ls_cicle=[]
for i in range(1,N*3):
  b=a
  a=ls_pass[a]
  if b==a:
    print(a)
    break
  elif a in ls_past:
    if c==0:
      c=i
      d=a
      ls_cicle.append(d)
      continue
    elif a==d:
      print(ls_cicle[(K-c)%(i-c)])
      break
    else:
      ls_cicle.append(a)
  elif i==K:
    print(a)
    break  
  else:
    ls_past.append(a)

Fixed submission:
N, K = map(int,input().split())
ls_pass = [0]+list(map(int,input().split()))
a=1
b=0

ls=["ンゴ"]+[0]+["ンゴ"]*(N-1)
ls_past=[1]
for i in range(1,N*3):
  b=a
  a=ls_pass[a]
  if ls[a]!="ンゴ":
    ls_cicle=ls_past[ls[a]:i]
    print(ls_cicle[(K-i)%len(ls_cicle)])
    break
  elif i==K:
    print(a)
    break  
  else:
    ls_past.append(a)
    ls[a]=i

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
ls_pass = list(map(int,input().split()))
ls_pass.insert(0,0)
a=1
b=0
ls_past=[1]
for i in range(1,N+1):
  b=a
  a=ls_pass[a]
  if b==a:
    print(a)
    break
  elif a in ls_past:
    c=ls_past.index(a)
    ls_cicle=ls_past[c:i]
    print(ls_cicle[(K-i)%(i-c)])
    break
  elif i==K:
    print(a)
    break
  else:
    ls_past.append(a)

Fixed submission:
N, K = map(int,input().split())
ls_pass = [0]+list(map(int,input().split()))
a=1
b=0

ls=["ンゴ"]+[0]+["ンゴ"]*(N-1)
ls_past=[1]
for i in range(1,N*3):
  b=a
  a=ls_pass[a]
  if ls[a]!="ンゴ":
    ls_cicle=ls_past[ls[a]:i]
    print(ls_cicle[(K-i)%len(ls_cicle)])
    break
  elif i==K:
    print(a)
    break  
  else:
    ls_past.append(a)
    ls[a]=i

Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
ls_pass = list(map(int,input().split()))
ls_pass.insert(0,0)
a=1
b=0
ls_past=[1]
for i in range(1,N+1):
  b=a
  a=ls_pass[a]
  if b==a:
    print(a)
    break
  elif a in ls_past:
    c=ls_past.index(a)
    ls_cicle=ls_past[c:i]
    print(ls_cicle[(K-i)%(i-c)])
    break
  elif i=K:
    print(a)
    break
  else:
    ls_past.append(a)

Fixed submission:
N, K = map(int,input().split())
ls_pass = [0]+list(map(int,input().split()))
a=1
b=0

ls=["ンゴ"]+[0]+["ンゴ"]*(N-1)
ls_past=[1]
for i in range(1,N*3):
  b=a
  a=ls_pass[a]
  if ls[a]!="ンゴ":
    ls_cicle=ls_past[ls[a]:i]
    print(ls_cicle[(K-i)%len(ls_cicle)])
    break
  elif i==K:
    print(a)
    break  
  else:
    ls_past.append(a)
    ls[a]=i

Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
List = list(map(int,input().split()))
Newlist = [1]
a=1
for i in range(N):
    a = List[a-1]
    if a==Newlist[i-1]:
        print(a)
        break
    elif a in Newlist:
        Cicle = Newlist[Newlist.index(a):Newlist[i-1]]
        print(Cicle[(K-i)%len(Cicle)-1])
        break
    else:
        Newlist.append(a)
else:
  print(a)

Fixed submission:
N, K = map(int,input().split())
ls_pass = [0]+list(map(int,input().split()))
a=1
b=0

ls=["ンゴ"]+[0]+["ンゴ"]*(N-1)
ls_past=[1]
for i in range(1,N*3):
  b=a
  a=ls_pass[a]
  if ls[a]!="ンゴ":
    ls_cicle=ls_past[ls[a]:i]
    print(ls_cicle[(K-i)%len(ls_cicle)])
    break
  elif i==K:
    print(a)
    break  
  else:
    ls_past.append(a)
    ls[a]=i

Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
List = list(map(int,input().split()))
Newlist = [1]
a=1
for i in range(N):
    a = List[a-1]
    if a==Newlist[i-1]:
        print(a)
        break
    elif a in Newlist:
        Cicle = Newlist[Newlist.index(a):Newlist[i-1]]
        print(Cicle[(K-i)%len(Cicle)-1])
        break
    else:
        Newlist.append(a)

Fixed submission:
N, K = map(int,input().split())
ls_pass = [0]+list(map(int,input().split()))
a=1
b=0

ls=["ンゴ"]+[0]+["ンゴ"]*(N-1)
ls_past=[1]
for i in range(1,N*3):
  b=a
  a=ls_pass[a]
  if ls[a]!="ンゴ":
    ls_cicle=ls_past[ls[a]:i]
    print(ls_cicle[(K-i)%len(ls_cicle)])
    break
  elif i==K:
    print(a)
    break  
  else:
    ls_past.append(a)
    ls[a]=i