Buggy python submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = [-1 for i in range(n+1)] #地点の数字に合わせる
points = []
order = {}
x = 1
T = -1

while visited[x] == -1:
  x = a[x-1] #添字に合わせた
  points.append(x)
  visited[x] = len(points)
T = len(points) - visited[x]
s = visited[x]
if k < s:
  print(points[k])
else:
  k -= s
  mod = k % T
  print(points[s+mod])
  

Fixed submission:
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = [-1 for i in range(n+1)] # 訪れていたら訪れたときの添字を格納する。
points = []
p = 1
while visited[p] == -1:
  visited[p] = len(points)
  points.append(p)
  p = a[p-1] #添字に直す

T = len(points) - visited[p]
s = visited[p]

if k < s:
  print(points[k])
else:
  mod = (k - s) % T
  print(points[s+mod])

Buggy python submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = []
order = {}
x = 1
T = -1
while T < 0:
  x = a[x-1] #添字に直す
  if x not in visited:
    visited.append(x)
    order[x] = len(visited)
  else:
    T = len(visited) - order[x]
    s = order[x]
if k < s:
  print(visited[k])
else:
  mod = (k-s) % T
  print(visited[s+mod])


Fixed submission:
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = [-1 for i in range(n+1)] # 訪れていたら訪れたときの添字を格納する。
points = []
p = 1
while visited[p] == -1:
  visited[p] = len(points)
  points.append(p)
  p = a[p-1] #添字に直す

T = len(points) - visited[p]
s = visited[p]

if k < s:
  print(points[k])
else:
  mod = (k - s) % T
  print(points[s+mod])

Buggy python submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = []
order = {}
x = 1
T = -1
while T < 0:
  x = a[x-1] #添字に直す
  if x not in visited:
    visited.append(x)
    order[x] = len(visited)-1
  else:
    T = (len(visited)-1) - order[x]
    s = order[x]
if k < s:
  print(visited[k])
else:
  mod = (k-s) % T
  print(visited[s+mod])


Fixed submission:
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = [-1 for i in range(n+1)] # 訪れていたら訪れたときの添字を格納する。
points = []
p = 1
while visited[p] == -1:
  visited[p] = len(points)
  points.append(p)
  p = a[p-1] #添字に直す

T = len(points) - visited[p]
s = visited[p]

if k < s:
  print(points[k])
else:
  mod = (k - s) % T
  print(points[s+mod])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(x) for x in input().split()]
a = [int(x)-1 for x in input().split()]

visited = [0]
order = {}
order[0] = 0
x = 0
T = -1
i = 0
while T<0:
  x = a[x]
  i+=1
  if x in visited:
    s = order[x]
    T = i - s
    break
  else:
    visited.append(x)
    order[x] = i
if k < s:
  print(visited[k]+1)
else:
  mod = (k-s) % T
  print(visited[s+mod]+1)


Fixed submission:
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = [-1 for i in range(n+1)] # 訪れていたら訪れたときの添字を格納する。
points = []
p = 1
while visited[p] == -1:
  visited[p] = len(points)
  points.append(p)
  p = a[p-1] #添字に直す

T = len(points) - visited[p]
s = visited[p]

if k < s:
  print(points[k])
else:
  mod = (k - s) % T
  print(points[s+mod])

Buggy python submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split()]
a = [int(x)-1 for x in input().split()]

visited = [0]
order = {}
x = 0
T = -1
i = 0
while T<0:
  x = a[x]
  i+=1
  if x in visited:
    T = i - order[x]
    s = order[x]
    break
  else:
    visited.append(x)
    order[x] = i
if k < s:
  print(visited[k])
else:
  mod = (k-s) % T
  print(visited[s+mod])


Fixed submission:
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = [-1 for i in range(n+1)] # 訪れていたら訪れたときの添字を格納する。
points = []
p = 1
while visited[p] == -1:
  visited[p] = len(points)
  points.append(p)
  p = a[p-1] #添字に直す

T = len(points) - visited[p]
s = visited[p]

if k < s:
  print(points[k])
else:
  mod = (k - s) % T
  print(points[s+mod])

Buggy python submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split()]
a = [int(x)-1 for x in input().split()]

visited = [0]
order = {}
x = 0
T = -1
i = 0
while T<0:
  x = a[x]
  i+=1
  if x in visited:
    T = i - order[x]
    s = order[x]
    break
  else:
    visited.append(x)
    order[x] = i
if k < s:
  print(visited[k])
else:
  mod = (k-s) % T
  print(visited[s+mod])

Fixed submission:
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = [-1 for i in range(n+1)] # 訪れていたら訪れたときの添字を格納する。
points = []
p = 1
while visited[p] == -1:
  visited[p] = len(points)
  points.append(p)
  p = a[p-1] #添字に直す

T = len(points) - visited[p]
s = visited[p]

if k < s:
  print(points[k])
else:
  mod = (k - s) % T
  print(points[s+mod])

Buggy python submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split()]
a = [int(x)-1 for x in input().split()]

visited = [0]
x = 0
T = -1
while T < 0:
  x = a[x]
  if x in visited:
    for j in range(i):
      if visited[j] == x:
        first = j
        break
    T = i - j
  else:
    visited.append(x)
  break
    
mod = (k-first) % T
print(a[first+mod]+1)


Fixed submission:
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = [-1 for i in range(n+1)] # 訪れていたら訪れたときの添字を格納する。
points = []
p = 1
while visited[p] == -1:
  visited[p] = len(points)
  points.append(p)
  p = a[p-1] #添字に直す

T = len(points) - visited[p]
s = visited[p]

if k < s:
  print(points[k])
else:
  mod = (k - s) % T
  print(points[s+mod])

Buggy python submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split()]
a = [int(x)-1 for x in input().split()]

visited = [0]
x = 0
for i in range(n):
  x = a[x]
  if x in visited:
    for j in range(i):
      if visited[j] == x:
        first = j
        break
    T = i - j
  break
  else:
    
mod = (k-first) % T
print(a[first+mod]+1)


Fixed submission:
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = [-1 for i in range(n+1)] # 訪れていたら訪れたときの添字を格納する。
points = []
p = 1
while visited[p] == -1:
  visited[p] = len(points)
  points.append(p)
  p = a[p-1] #添字に直す

T = len(points) - visited[p]
s = visited[p]

if k < s:
  print(points[k])
else:
  mod = (k - s) % T
  print(points[s+mod])

Buggy python submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split()]
a = [int(x)-1 for x in input().split()]

visited = []
x=0
for i in range(n):
  x = a[x]
  if x in visited:
    for j in range(i):
      if visited[j] == x:
        first = j
        break
    T = i - j
  break
  else:
    visited.append(a[i])
mod = (k-first) % T
print(a[first+mod]+1)


Fixed submission:
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = [-1 for i in range(n+1)] # 訪れていたら訪れたときの添字を格納する。
points = []
p = 1
while visited[p] == -1:
  visited[p] = len(points)
  points.append(p)
  p = a[p-1] #添字に直す

T = len(points) - visited[p]
s = visited[p]

if k < s:
  print(points[k])
else:
  mod = (k - s) % T
  print(points[s+mod])

Buggy python submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = []
x=0
for i in range(n):
  x = a[x]
  if x in visited:
    for j in range(i):
      if visited[j] == x:
        first = j
        break
    T = i - j
    break
  else:
    visited.append(a[i])
mod = (k-first) % T
print(a[first+mod]+1)


Fixed submission:
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = [-1 for i in range(n+1)] # 訪れていたら訪れたときの添字を格納する。
points = []
p = 1
while visited[p] == -1:
  visited[p] = len(points)
  points.append(p)
  p = a[p-1] #添字に直す

T = len(points) - visited[p]
s = visited[p]

if k < s:
  print(points[k])
else:
  mod = (k - s) % T
  print(points[s+mod])

Buggy python submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = [0]
x=1
for i in range(n):
  x = a[i]
  if x in visited:
    for j in range(i):
      if visited[j] == x:
        first = j
        break
    T = i - j
  else:
    visited.append(a[i])
mod = (k-first) % T
print(a[first+mod])


Fixed submission:
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = [-1 for i in range(n+1)] # 訪れていたら訪れたときの添字を格納する。
points = []
p = 1
while visited[p] == -1:
  visited[p] = len(points)
  points.append(p)
  p = a[p-1] #添字に直す

T = len(points) - visited[p]
s = visited[p]

if k < s:
  print(points[k])
else:
  mod = (k - s) % T
  print(points[s+mod])

Buggy python submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

x = 0
for i in range(k):
  x = a[x]
print(x+1)

Fixed submission:
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

visited = [-1 for i in range(n+1)] # 訪れていたら訪れたときの添字を格納する。
points = []
p = 1
while visited[p] == -1:
  visited[p] = len(points)
  points.append(p)
  p = a[p-1] #添字に直す

T = len(points) - visited[p]
s = visited[p]

if k < s:
  print(points[k])
else:
  mod = (k - s) % T
  print(points[s+mod])