Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = [int(i) - 1 for i in input().split()]
r = []
nx = 0
for i in range(n):
    r.append(nx)
    if k < i:
        print(r[k] + 1)
        break
    if a[nx] in r:
        m = r.index(a[nx])
        d = i - m + 1
        k = k - m
        k = k % d
        print(r[k + m] + 1)
        break  
    nx = a[nx]


Fixed submission:
n,k = map(int,input().split())
a = [int(i) - 1 for i in input().split()]
r = []
nx = 0
sr = set([])
for i in range(n):
    r.append(nx)
    sr.add(nx)
    if k < i:
        print(r[k] + 1)
        break
    tnx = a[nx]
    if tnx in sr:
        m = r.index(a[nx])
        d = i - m + 1
        k = k - m
        k = k % d
        print(r[k + m] + 1)
        break  
    nx = tnx

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = [int(i) - 1 for i in input().split()]
r = []
nx = 0
for i in range(n):
    r.append(nx)
    if k < i:
        print(r[k] + 1)
        break
    if a[nx] in r:
        m = r.index(a[nx])
        d = i - m + 1
        k = k - m
        k = k % d
        print(r[k + m] + 1)
        break  
    nx = a[nx]


Fixed submission:
n,k = map(int,input().split())
a = [int(i) - 1 for i in input().split()]
r = []
nx = 0
sr = set([])
for i in range(n):
    r.append(nx)
    sr.add(nx)
    if k < i:
        print(r[k] + 1)
        break
    tnx = a[nx]
    if tnx in sr:
        m = r.index(a[nx])
        d = i - m + 1
        k = k - m
        k = k % d
        print(r[k + m] + 1)
        break  
    nx = tnx

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = [int(i) - 1 for i in input().split()]
r = []
nx = 0
for i in range(n):
    r.append(nx)
    if k < i:
        print(r[k] + 1)
        break
    if a[nx] in r:
        m = r.index(a[nx])
        d = i - m
        k = k - m
        k = k % d
        print(r[k + 1] + 1)
        break  
    nx = a[nx]


Fixed submission:
n,k = map(int,input().split())
a = [int(i) - 1 for i in input().split()]
r = []
nx = 0
sr = set([])
for i in range(n):
    r.append(nx)
    sr.add(nx)
    if k < i:
        print(r[k] + 1)
        break
    tnx = a[nx]
    if tnx in sr:
        m = r.index(a[nx])
        d = i - m + 1
        k = k - m
        k = k % d
        print(r[k + m] + 1)
        break  
    nx = tnx

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = [int(i) - 1 for i in input().split()]
r = []
nx = 0
for i in range(n):
    r.append(nx)
    if k < i:
        print(r[k] + 1)
        break
    if a[nx] in r:
        if k >= len(r):
            m = r.index(a[nx])
            d = i - m
            k = k - m
            k = k % d
            print(r[k + 1] + 1)
            break  
    nx = a[nx]


Fixed submission:
n,k = map(int,input().split())
a = [int(i) - 1 for i in input().split()]
r = []
nx = 0
sr = set([])
for i in range(n):
    r.append(nx)
    sr.add(nx)
    if k < i:
        print(r[k] + 1)
        break
    tnx = a[nx]
    if tnx in sr:
        m = r.index(a[nx])
        d = i - m + 1
        k = k - m
        k = k % d
        print(r[k + m] + 1)
        break  
    nx = tnx

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = [int(i) - 1 for i in input().split()]
r = []
nx = 0
for i in range(n):
    r.append(nx)
    if a[nx] in r:
        m = r.index(a[nx])
        d = i - m
        k = k - m
        k = k % d
        print(r[k + 1] + 1)
        break
    nx = a[nx]
    
    




Fixed submission:
n,k = map(int,input().split())
a = [int(i) - 1 for i in input().split()]
r = []
nx = 0
sr = set([])
for i in range(n):
    r.append(nx)
    sr.add(nx)
    if k < i:
        print(r[k] + 1)
        break
    tnx = a[nx]
    if tnx in sr:
        m = r.index(a[nx])
        d = i - m + 1
        k = k - m
        k = k % d
        print(r[k + m] + 1)
        break  
    nx = tnx