Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

array = input().split()
for i in range(len(array)):
    array[i] = int(array[i])

now = 1

history = set()
start_number = -1

for i in range(K):
    history.add(now)
    now = array[now - 1]
    if(now in history):
        start_number = now
        break

if not(start_number == -1):
    start_ind = history.index(start_number)
    length = len(history) - start_ind
    mod = (K - start_ind) % length
    now = history[start_ind + mod]

print(now)


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

array = input().split()
for i in range(len(array)):
    array[i] = int(array[i])

now = 1

history = []
sethistory = set()
start_number = -1

for i in range(K):
    history.append(now)
    sethistory.add(now)
    now = array[now - 1]
    if(now in sethistory):
        start_number = now
        break

if not(start_number == -1):
    start_ind = history.index(start_number)
    length = len(history) - start_ind
    mod = (K - start_ind) % length
    now = history[start_ind + mod]

print(now)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

array = input().split()
for i in range(len(array)):
    array[i] = int(array[i])

now = 1

history = set()
start_number = -1

for i in range(K):
    history.append(now)
    now = array[now - 1]
    if(now in history):
        start_number = now
        break

if not(start_number == -1):
    start_ind = history.index(start_number)
    length = len(history) - start_ind
    mod = (K - start_ind) % length
    now = history[start_ind + mod]

print(now)


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

array = input().split()
for i in range(len(array)):
    array[i] = int(array[i])

now = 1

history = []
sethistory = set()
start_number = -1

for i in range(K):
    history.append(now)
    sethistory.add(now)
    now = array[now - 1]
    if(now in sethistory):
        start_number = now
        break

if not(start_number == -1):
    start_ind = history.index(start_number)
    length = len(history) - start_ind
    mod = (K - start_ind) % length
    now = history[start_ind + mod]

print(now)

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

array = input().split()
for i in range(len(array)):
    array[i] = int(array[i])

now = 1

history = []
start_number = -1

for i in range(K):
    history.append(now)
    now = array[now - 1]
    if(now in history):
        start_number = now
        break

if not(start_number == -1):
    start_ind = history.index(start_number)
    length = len(history) - start_ind
    mod = (K - start_ind) % length
    now = history[start_ind + mod]

print(now)


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

array = input().split()
for i in range(len(array)):
    array[i] = int(array[i])

now = 1

history = []
sethistory = set()
start_number = -1

for i in range(K):
    history.append(now)
    sethistory.add(now)
    now = array[now - 1]
    if(now in sethistory):
        start_number = now
        break

if not(start_number == -1):
    start_ind = history.index(start_number)
    length = len(history) - start_ind
    mod = (K - start_ind) % length
    now = history[start_ind + mod]

print(now)