Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))  # 1-indexed


journey = [1]  # 道順

for i in range(2**n):
    nxt = a[journey[-1]]
    journey.append(nxt)

if k <= n:
    print(journey[k])
    exit()

# k > n
loop_end = n

loop_start = n - 1  # ループの始まりのindex

while(journey[loop_start] != journey[loop_end]):
    loop_start -= 1

period = loop_end - loop_start

k %= period

while k < n:
    k += period
    
print(journey[k])
    

Fixed submission:
from collections import defaultdict

n, k = map(int, input().split())
*a, = map(int, input().split())
a = [a[i] - 1 for i in range(n)]
ans = 0

if k <= n:
    i = 0
    while(k > 0):
        ans = a[i]
        i = a[i]
        k -= 1
        # print(ans + 1)
    ans += 1

else:
    # 周期の場所をチェック
    start_period = 1
    period_i = -1
    d = defaultdict(int)
    d[0] = 1
    i = 0
    count = 1
    while(1):
        # print(f'i = {i}, count = {count}')
        if a[i] in d.keys():
            period_i = count
            start_period = d[a[i]]
            break

        d[a[i]] = count + 1
        i = a[i]
        count += 1
        
    # 逆引き
    d_r = {i:k for k, i in d.items()}
    # print('d: ', d)
    # print('d_r: ', d_r)
    # print('period_i:', period_i)
    # print('start_period:', start_period)
    # print(f'{k - (start_period - 1)}')
    # print(f'{(k - (start_period - 1)) % (period_i - start_period + 1)}')
    # print('d_r[start_period]: ', d_r[start_period])
    # print(d_r[start_period + ((k - (start_period - 1)) % (period_i - start_period + 1))])
    ans = d_r[start_period + ((k - (start_period - 1)) % (period_i - start_period + 1))] + 1
    
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))  # 1-indexed


journey = [1]  # 道順

for i in range(2**n):
    nxt = a[journey[-1]]
    journey.append(nxt)

if k <= n:
    print(journey[k])
    exit()

# k > n
loop_end = journey[n]

loop_start = n - 1  # ループの始まりのindex

while(journey[loop_start] != loop_end):
    loop_start -= 1

period = loop_end - loop_start

k %= period

while k < n:
    k += period
    
print(journey[period])
    

Fixed submission:
from collections import defaultdict

n, k = map(int, input().split())
*a, = map(int, input().split())
a = [a[i] - 1 for i in range(n)]
ans = 0

if k <= n:
    i = 0
    while(k > 0):
        ans = a[i]
        i = a[i]
        k -= 1
        # print(ans + 1)
    ans += 1

else:
    # 周期の場所をチェック
    start_period = 1
    period_i = -1
    d = defaultdict(int)
    d[0] = 1
    i = 0
    count = 1
    while(1):
        # print(f'i = {i}, count = {count}')
        if a[i] in d.keys():
            period_i = count
            start_period = d[a[i]]
            break

        d[a[i]] = count + 1
        i = a[i]
        count += 1
        
    # 逆引き
    d_r = {i:k for k, i in d.items()}
    # print('d: ', d)
    # print('d_r: ', d_r)
    # print('period_i:', period_i)
    # print('start_period:', start_period)
    # print(f'{k - (start_period - 1)}')
    # print(f'{(k - (start_period - 1)) % (period_i - start_period + 1)}')
    # print('d_r[start_period]: ', d_r[start_period])
    # print(d_r[start_period + ((k - (start_period - 1)) % (period_i - start_period + 1))])
    ans = d_r[start_period + ((k - (start_period - 1)) % (period_i - start_period + 1))] + 1
    
    
print(ans)