Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [-1] * (n+1)
now = 1
history = []

while b[now] == -1:
  b[now] = len(history)
  history.append(now)
  now = a[now-1]  

if now == 1:
    print(history[k % len(history)])
else:
    print(history[(k - now) % (len(history) - now) + now])

Fixed submission:
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [-1] * (n+1)
now = 1
history = []

while b[now] == -1:
  b[now] = len(history)
  history.append(now)
  now = a[now-1]

c = len(history) - b[now]
l = b[now]

if k < l:
  print(history[k])
else:
  k -= l
  k %= c
  print(history[l+k])

Buggy python submission (verdict: Runtime Error):
import sys
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [-1] * n
now = 0
count = 0
history = []

while b[now] == -1:
  history.append(now+1)
  b[now] = count
  count += 1
  if count == k:
    print(a[now])
    sys.exit()
  if a[now] == now+1:
    print(a[now])
    sys.exit()
  now = a[now]-1

if now != 0:
  k -= now+1
  for i in range(now+1):
    history.pop(0)     

print(history[k % len(history)])

Fixed submission:
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [-1] * (n+1)
now = 1
history = []

while b[now] == -1:
  b[now] = len(history)
  history.append(now)
  now = a[now-1]

c = len(history) - b[now]
l = b[now]

if k < l:
  print(history[k])
else:
  k -= l
  k %= c
  print(history[l+k])

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [False] * n
now = 0
count = 0
history = [1]
flag = True

while b[now] == False:
  history.append(a[now])
  b[now] = True
  count += 1
  if count >= k:
    print(a[now])
    flag = False
    break
  if a[now]-1 == now:
    print(a[now])
    flag = False
    break
  now = a[now]-1
  
if flag == True:
  if now != 0:
    k -= now + 1
    history = history[now+1:]
  history.pop()
  print(history[k % len(history)])


Fixed submission:
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [-1] * (n+1)
now = 1
history = []

while b[now] == -1:
  b[now] = len(history)
  history.append(now)
  now = a[now-1]

c = len(history) - b[now]
l = b[now]

if k < l:
  print(history[k])
else:
  k -= l
  k %= c
  print(history[l+k])

Buggy python submission (verdict: Runtime Error):
import sys
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [False] * n
now = 0
count = 0
history = [1]

while b[now] == False:
  history.append(a[now])
  b[now] = True
  count += 1
  if count >= k:
    print(a[now])
    sys.exit()
  if a[now]-1 == now:
    print(a[now])
    sys.exit()
  now = a[now]-1


if now != 0:
  k -= now + 1
  history = history[now+1:]
history.pop()
print(history[k % len(history)])


Fixed submission:
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [-1] * (n+1)
now = 1
history = []

while b[now] == -1:
  b[now] = len(history)
  history.append(now)
  now = a[now-1]

c = len(history) - b[now]
l = b[now]

if k < l:
  print(history[k])
else:
  k -= l
  k %= c
  print(history[l+k])

Buggy python submission (verdict: Runtime Error):
import sys
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [False] * n
now = 0
count = 0
history = [1]

while b[now] == False:
  history.append(a[now])
  b[now] = True
  count += 1
  if count >= k:
    print(a[now])
    sys.exit()
  now = a[now]-1

if now != 0:
  k -= now + 1
  history = history[now+1:]
history.pop()
print(history[k % len(history)])


Fixed submission:
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [-1] * (n+1)
now = 1
history = []

while b[now] == -1:
  b[now] = len(history)
  history.append(now)
  now = a[now-1]

c = len(history) - b[now]
l = b[now]

if k < l:
  print(history[k])
else:
  k -= l
  k %= c
  print(history[l+k])