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

def bin(arr,val):
    left,right = 0,len(arr)-1
    while left<=right:
        mid = (left+right)//2
        if arr[mid]==val: return 1
        elif arr[mid]<val: left = mid + 1
        else: right = mid - 1
    return 0

know = []
now = 1
while not bin(know, now):
    know.append(now)
    now = a[now]

start = a[know[-1]]
for i,num in enumerate(know):
    if num == start: loop = know[i:] ; break

#print(know,start,loop)

if k < len(know):
    ans = know[k]
else:
    k - = len(know)
    ans = know[k%len(loop)]


print(ans)


Fixed submission:
n,k = map(int,input().split())
a = [0]+list(map(int,input().split()))

def bin(arr,val):
    left,right = 0,len(arr)-1
    while left<=right:
        mid = (left+right)//2
        if arr[mid]==val: return 1
        elif arr[mid]<val: left = mid + 1
        else: right = mid - 1
    return 0

know = []
now = 1
while not bin(know, now):
    know.append(now)
    now = a[now]

start = a[know[-1]]
for i,num in enumerate(know):
    if num == start: loop = know[i:] ; break

#print(know,start,loop)

if k < len(know):
    ans = know[k]
else:
    k -= len(know)
    ans = loop[k%len(loop)]

print(ans)

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

def bin(arr,val):
    left,right = 0,len(arr)-1
    while left<=right:
        mid = (left+right)//2
        if arr[mid]==val: return 1
        elif arr[mid]<val: left = mid + 1
        else: right = mid - 1
    return 0

know = []
now = 1
while not bin(know, now):
    know.append(now)
    now = a[now]

start = a[know[-1]]
for i,num in enumerate(know):
    if num == start: loop = know[i:] ; break

print(know,start,loop)

if k < len(know):
    ans = know[k]
else:
    k - = len(know)
    ans = know[k%len(loop)]


print(ans)


Fixed submission:
n,k = map(int,input().split())
a = [0]+list(map(int,input().split()))

def bin(arr,val):
    left,right = 0,len(arr)-1
    while left<=right:
        mid = (left+right)//2
        if arr[mid]==val: return 1
        elif arr[mid]<val: left = mid + 1
        else: right = mid - 1
    return 0

know = []
now = 1
while not bin(know, now):
    know.append(now)
    now = a[now]

start = a[know[-1]]
for i,num in enumerate(know):
    if num == start: loop = know[i:] ; break

#print(know,start,loop)

if k < len(know):
    ans = know[k]
else:
    k -= len(know)
    ans = loop[k%len(loop)]

print(ans)

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

know = []
now = 1
cnt = 0
while 1:
    if now in know: break
    know.append(now)
    now = a[now]

start = a[know[-1]]
for i,num in enumerate(know):
    if num == start: loop = know[i:] ; break

#print(know,start,loop)

cnt = len(loop)
if k>=len(know):
    k -= len(know)
    ans = loop[k%cnt]

else:
    ans = know[k]

print(ans)


Fixed submission:
n,k = map(int,input().split())
a = [0]+list(map(int,input().split()))

def bin(arr,val):
    left,right = 0,len(arr)-1
    while left<=right:
        mid = (left+right)//2
        if arr[mid]==val: return 1
        elif arr[mid]<val: left = mid + 1
        else: right = mid - 1
    return 0

know = []
now = 1
while not bin(know, now):
    know.append(now)
    now = a[now]

start = a[know[-1]]
for i,num in enumerate(know):
    if num == start: loop = know[i:] ; break

#print(know,start,loop)

if k < len(know):
    ans = know[k]
else:
    k -= len(know)
    ans = loop[k%len(loop)]

print(ans)

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

know = []
now = 1
cnt = 0
while 1:
    if now in know: break
    know.append(now)
    now = a[now]

start = a[know[-1]]
for i,num in enumerate(know):
    if num == start: loop = know[i:] ; break

#print(know,start,loop)

cnt = len(loop)
if k>=len(know):
    k -= len(know)
    ans = loop[k%cnt]

else:
    ans = know[k]

print(ans)


Fixed submission:
n,k = map(int,input().split())
a = [0]+list(map(int,input().split()))

def bin(arr,val):
    left,right = 0,len(arr)-1
    while left<=right:
        mid = (left+right)//2
        if arr[mid]==val: return 1
        elif arr[mid]<val: left = mid + 1
        else: right = mid - 1
    return 0

know = []
now = 1
while not bin(know, now):
    know.append(now)
    now = a[now]

start = a[know[-1]]
for i,num in enumerate(know):
    if num == start: loop = know[i:] ; break

#print(know,start,loop)

if k < len(know):
    ans = know[k]
else:
    k -= len(know)
    ans = loop[k%len(loop)]

print(ans)