Buggy python submission (verdict: Runtime Error):
n, k = map(int,input().split())
a = list(map(int,input().split()))

route = []
i = 0

while True:
    ne = a[i]

    if i not in route and len(route) <= k:
        route.append(i)
    else:
        temp = len(route) - len(route[i:])
        if k <= temp:
            print(route[k] + 1)
            # print([i+1 for i in route])
        else:
            print(a[(k-temp)%len(route[i:])])
        break

    i = ne - 1

Fixed submission:
from collections import defaultdict

n, k = map(int,input().split())
a = list(map(int,input().split()))

route = defaultdict(int)
i = 0
loop = []
tail = []

while route[i] < 2:

    if route[i] == 0:
        tail.append(i)
    else:
        loop.append(i)
    
    route[i] += 1
    i = a[i] - 1

if len(tail) > k:
    print(tail[k] + 1)
else:
    temp = len(tail) - len(loop)
    print(loop[(k-temp) % len(loop)] + 1)

Buggy python submission (verdict: Runtime Error):
n, k = map(int,input().split())
a = list(map(int,input().split()))

route = []
i = 0

while True:
    ne = a[i]

    if i not in route:
        route.append(i)
    else:
        temp = len(route) - len(route[i:])
        if k <= temp:
            print(route[k])
        else:
            print(a[(k-temp)%len(route[i:])])
        break

    i = ne - 1

Fixed submission:
from collections import defaultdict

n, k = map(int,input().split())
a = list(map(int,input().split()))

route = defaultdict(int)
i = 0
loop = []
tail = []

while route[i] < 2:

    if route[i] == 0:
        tail.append(i)
    else:
        loop.append(i)
    
    route[i] += 1
    i = a[i] - 1

if len(tail) > k:
    print(tail[k] + 1)
else:
    temp = len(tail) - len(loop)
    print(loop[(k-temp) % len(loop)] + 1)

Buggy python submission (verdict: Runtime Error):
n, k = map(int,input().split())
a = list(map(int,input().split()))

route = []
i = 0

# 方針は合っていたが，
while True:
    ne = a[i]

    if i not in route:
        route.append(i)
    else:
        temp = len(route) - len(route[i:])
        if k < temp:
            print(a[k])
        else:
            print(a[(k-temp)%len(route[i:])])
        break

    i = ne - 1

Fixed submission:
from collections import defaultdict

n, k = map(int,input().split())
a = list(map(int,input().split()))

route = defaultdict(int)
i = 0
loop = []
tail = []

while route[i] < 2:

    if route[i] == 0:
        tail.append(i)
    else:
        loop.append(i)
    
    route[i] += 1
    i = a[i] - 1

if len(tail) > k:
    print(tail[k] + 1)
else:
    temp = len(tail) - len(loop)
    print(loop[(k-temp) % len(loop)] + 1)

Buggy python submission (verdict: Runtime Error):
n, k = map(int,input().split())
a = list(map(int,input().split()))

route = []
i = 0

while True:
    ne = a[i]

    if i not in route:
        route.append(i)
    else:
        temp = len(route) - len(route[i:])
        print(a[(k-temp)%len(route[i:])])
        break

    i = ne - 1

Fixed submission:
from collections import defaultdict

n, k = map(int,input().split())
a = list(map(int,input().split()))

route = defaultdict(int)
i = 0
loop = []
tail = []

while route[i] < 2:

    if route[i] == 0:
        tail.append(i)
    else:
        loop.append(i)
    
    route[i] += 1
    i = a[i] - 1

if len(tail) > k:
    print(tail[k] + 1)
else:
    temp = len(tail) - len(loop)
    print(loop[(k-temp) % len(loop)] + 1)

Buggy python submission (verdict: Runtime Error):
n, k = map(int,input().split())
a = list(map(int,input().split()))

route = []
i = 0

while True:
    ne = a[i]

    if i not in route:
        route.append(i)
    else:
        k = k - (len(route) - len(route[i:]))
        print(a[k%len(route[i:])])
        break

    i = ne - 1

Fixed submission:
from collections import defaultdict

n, k = map(int,input().split())
a = list(map(int,input().split()))

route = defaultdict(int)
i = 0
loop = []
tail = []

while route[i] < 2:

    if route[i] == 0:
        tail.append(i)
    else:
        loop.append(i)
    
    route[i] += 1
    i = a[i] - 1

if len(tail) > k:
    print(tail[k] + 1)
else:
    temp = len(tail) - len(loop)
    print(loop[(k-temp) % len(loop)] + 1)

Buggy python submission (verdict: Runtime Error):
n, k = map(int,input().split())
a = list(map(int,input().split()))

route = []
i = 0
count = 0

while count < k:
    ne = a[i]
    count += 1

    if i not in route:
        route.append(i)
    else:
        k = k - (len(route) - len(route[i:]))
        print(a[k%len(route[i:])])
        break

    i = ne - 1

Fixed submission:
from collections import defaultdict

n, k = map(int,input().split())
a = list(map(int,input().split()))

route = defaultdict(int)
i = 0
loop = []
tail = []

while route[i] < 2:

    if route[i] == 0:
        tail.append(i)
    else:
        loop.append(i)
    
    route[i] += 1
    i = a[i] - 1

if len(tail) > k:
    print(tail[k] + 1)
else:
    temp = len(tail) - len(loop)
    print(loop[(k-temp) % len(loop)] + 1)