Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
l1=[a[0]]
l2=[]
def al(num):
    l1.append(num)
def n1(num):
    for j in range(num):
        if l1[j]==num1:
            break
    return j
def n2(num5):
    return num5 in l1
for i in range(n):
    num1=a[l1[-1]-1]
    str=n2(num1)
    if str==True:
        break
    else:
        al(num1)
num=n1(len(l1))
l2=l1[num:]
l1=l1[:num]
num1=len(l1)
num2=len(l2)
if k<=num1:
    print(l1[k-1])
else:
    num3=(k-num1)%num2
    print(l2[num3-1])


Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
l1=set([a[0]])
num1=a[0]
num2=1
l2=[]
def al(num):
    l1.add(num)
def n2(num5):
    return num5 in l1
for i in range(n):
    num1=a[num1-1]
    al(num1)
    if num2==len(l1):
        break
    else:
        num2=len(l1)
l1=list(l1)
num=l1.index(num1)
l2=l1[num:]
l1=l1[:num]
num1=len(l1)
num2=len(l2)
if k<=num1:
    print(l1[k-1])
else:
    num3=(k-num1)%num2
    print(l2[num3-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
l1=[a[0]]
l2=[]
def al(num):
    l1.append(num)
for i in range(n):
    num1=a[l1[-1]-1]
    str=num1 in l1
    if str==True:
        for j in range(len(l1)):
            if l1[j]==num1:
                break
        l2=l1[j:]
        l1=l1[:j]
        break
    else:
        al(num1)
num1=len(l1)
num2=len(l2)
if k<=num1:
    print(l1[k-1])
else:
    num3=(k-num1)%num2
    print(l2[num3-1])


Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
l1=set([a[0]])
num1=a[0]
num2=1
l2=[]
def al(num):
    l1.add(num)
def n2(num5):
    return num5 in l1
for i in range(n):
    num1=a[num1-1]
    al(num1)
    if num2==len(l1):
        break
    else:
        num2=len(l1)
l1=list(l1)
num=l1.index(num1)
l2=l1[num:]
l1=l1[:num]
num1=len(l1)
num2=len(l2)
if k<=num1:
    print(l1[k-1])
else:
    num3=(k-num1)%num2
    print(l2[num3-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
numlist=[]
count=1
count2=0
num=0
for i in range(n):
    count2=a[count-1]
    if count2 in numlist =="True":
        break
    numlist.append(count2)
    count=count2
for i in range(len(numlist)):
    if numlist[i]==count2:
        num=i+1
        break
numlist2=numlist[num:]
if len(numlist)>k:
    print(numlist[k-1])
else:
    b=(k-num)%(len(numlist2))
    if b==0:
        print(numlist2[len(numlist2)-1])
    else:
        print(numlist2[b-1])


Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
l1=set([a[0]])
num1=a[0]
num2=1
l2=[]
def al(num):
    l1.add(num)
def n2(num5):
    return num5 in l1
for i in range(n):
    num1=a[num1-1]
    al(num1)
    if num2==len(l1):
        break
    else:
        num2=len(l1)
l1=list(l1)
num=l1.index(num1)
l2=l1[num:]
l1=l1[:num]
num1=len(l1)
num2=len(l2)
if k<=num1:
    print(l1[k-1])
else:
    num3=(k-num1)%num2
    print(l2[num3-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
numlist=[]
count=1
count2=0
num=0
for i in range(n):
    count2=a[count-1]
    if count2 in numlist =="True":
        break
    numlist.append(count2)
    count=count2
for i in range(len(numlist)):
    if numlist[i]==count2:
        num=i+1
        break
numlist2=numlist[num:]
if len(numlist)>k:
    print(numlist[k-1])
else:
    b=(k-num)%(len(numlist2))
    if b==0:
        print(numlist2[len(numlist2)-1])
    else:
        print(numlist2[b-1])


Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
l1=set([a[0]])
num1=a[0]
num2=1
l2=[]
def al(num):
    l1.add(num)
def n2(num5):
    return num5 in l1
for i in range(n):
    num1=a[num1-1]
    al(num1)
    if num2==len(l1):
        break
    else:
        num2=len(l1)
l1=list(l1)
num=l1.index(num1)
l2=l1[num:]
l1=l1[:num]
num1=len(l1)
num2=len(l2)
if k<=num1:
    print(l1[k-1])
else:
    num3=(k-num1)%num2
    print(l2[num3-1])