Harryxun/stf_run huggingface dataset:
n,m = [int(x) for x in input().split()]
sc = {}
out = False
for _ in range(m):
    s,c = [x for x in input().split()]
    if s in sc.keys():
        if sc[s] != c:
            print("-1")
            out = True
        else:
            sc[s] = c
    else:
        sc[s] = c
        

if not out:
    if n == 1:
        print(sc["1"])
    elif n == 2:
        if "1" in sc.keys():
            if sc["1"] != "0":
                if "2" in sc.keys():
                    print(sc["1"],sc["2"],sep="")
                else:
                    sc["2"] = "0"
                    print(sc["1"],sc["2"],sep="")
            else:
                print("-1")
        else:
            sc["1"] = "1"
            print(sc["1"],sc["2"],sep="")
    elif n == 3:
        if "1" in sc.keys():
            if sc["1"] != "0":
                if "2" in sc.keys():
                    if "3" in sc.keys():
                        print(sc["1"],sc["2"],sc["3"],sep="")
                    else:
                        sc["3"] = "0"
                        print(sc["1"],sc["2"],sc["3"],sep="")
                else:
                    sc["2"] = "0"
                    if "3" in sc.keys():
                        print(sc["1"],sc["2"],sc["3"],sep="")
                    else:
                        sc["3"] = "0"
                        print(sc["1"],sc["2"],sc["3"],sep="")
            else:
                print("-1")
        else:
            sc["1"] = "1"
            if not "2" in sc.keys():
                sc["2"] = "0"
            if not "3" in sc.keys():
                sc["3"] = "0"
            print(sc["1"],sc["2"],sc["3"],sep="")

### FIXED CODE ###

n,m = [int(x) for x in input().split()]
sc = {}
out = False
for _ in range(m):
    s,c = [x for x in input().split()]
    if s in sc.keys():
        if sc[s] != c:
            print("-1")
            out = True
        else:
            sc[s] = c
    else:
        sc[s] = c
        

if not out:
    if n == 1:
        if not "1" in sc.keys():
            sc["1"] = "0"
        print(sc["1"])
    elif n == 2:
        if not "1" in sc.keys():
            sc["1"] = "1"
            if not "2" in sc.keys():
                sc["2"] = "0"
            print(sc["1"],sc["2"],sep="")
        else:
            if sc["1"] == "0":
                print("-1")
            else:
                if not "2" in sc.keys():
                    sc["2"] = "0"
                print(sc["1"],sc["2"],sep="")
    elif n == 3:
        if not "1" in sc.keys():
            sc["1"] = "1"
            if not "2" in sc.keys():
                sc["2"] = "0"
            if not "3" in sc.keys():
                sc["3"] = "0"
            print(sc["1"],sc["2"],sc["3"],sep="")
        else:
            if sc["1"] == "0":
                print("-1")
            else:
                if not "2" in sc.keys():
                    sc["2"] = "0"
                if not "3" in sc.keys():
                    sc["3"] = "0"
                print(sc["1"],sc["2"],sc["3"],sep="")
a, b, k = map(int, input().split())

div=[]
for i in range(1,max(a,b)):
    if(a%i==0 and b%i==0):
        div.append(i)
if(div):
    div.reverse()
    print(div[k-1])
else:
    print(1)


### FIXED CODE ###

a, b, k = map(int, input().split())

div=[]
for i in range(1,min(a,b)+1):
    if(a%i==0 and b%i==0):
        div.append(i)
if(div):
    div.reverse()
    print(div[k-1])
else:
    print(1)
x1, y1, x2, y2 = map(int, input().split())
diff_x, diff_y = x2 - x1, y2 - y1

x3 = x2	- diff_y
y3 = y2 + diff_x

x4 = x1	- diff_y
y4 = y1 + diff_x


print(x3, y3, x4, y4)


### FIXED CODE ###

k = int(input())
if k % 2 == 0:
    print( (k // 2) * (k // 2 ))
else:
    print( ((k - 1) // 2 + 1) * ((k - 1) // 2) )
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n,x = map(int,input().split())
s = list(map(int,input().split()))
mod = 10**9 + 7
s.sort()
s = s[::-1]
c = max(max(s),x)
dp = [[0]*(c+1) for i in range(n+1)]
dp[0][x] = 1
for i in range(n):
    for j in range(c+1):
        dp[i+1][j%s[i]] += dp[i][j]
        dp[i+1][j%s[i]] %= mod
        dp[i+1][j] += dp[i][j]*(n-i-1)
        dp[i+1][j] %= mod
ans = 0
for i in range(c+1):
        ans += dp[n][i]*i
        ans %= mod
print(ans)
if n <= 10000:
  print(9)

### FIXED CODE ###

import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n,q = map(int,input().split())
s = input().strip()
a = [list(input().split()) for i in range(q)]
def cheak(x):
  for i in range(q):
      if s[x] == a[i][0]:
          if a[i][1] == "L":
              x-=1
          else:
              x+=1
      if x >= n :
          return 0
      elif x < 0:
          return 1
  return 0
def cheak2(x):
  for i in range(q):
      if s[x] == a[i][0]:
          if a[i][1] == "L":
              x-=1
          else:
              x+=1
      if x >= n :
          return 1
      elif x < 0:
          return 0
  return 0
dai = n-1
syo = 0
hi = cheak(syo)
mi = cheak2(dai)
if hi== 0 and mi==0:
    print(n)
elif hi and mi:
  while True:
    if dai-syo <= 1:
        if cheak(dai) != 1:
            dai = syo
        break
    kon = (dai+syo)//2
    c = cheak(kon)
    if c == 0:
        dai = kon
    else:
        syo = kon
  ab = dai
  dai = n-1
  syo = 0
  while True:
    if dai-syo <= 1:
        if cheak2(syo) == 1:
            dai = syo
        break
    kon = (dai+syo)//2
    c = cheak2(kon)
    if c == 1:
        dai = kon
    else:
        syo = kon
  if dai <= ab:
      print(0)
      exit()
  print(n-(ab+1+n-dai))
elif hi==1 and mi == 0:
  while True:
    if dai-syo <= 1:
        if cheak(dai) != 1:
            dai = syo
        break
    kon = (dai+syo)//2
    c = cheak(kon)
    if c == 0:
        dai = kon
    else:
        syo = kon
  print(n-1-dai)
else:
  while True:
    if dai-syo <= 1:
        if cheak2(syo) == 1:
            dai = syo
        break
    kon = (dai+syo)//2
    c = cheak2(kon)
    if c == 1:
        dai = kon
    else:
        syo = kon
  print(dai)
S = input()

ok_list = ["A", "C", "G", "T"]
ans_list = []
ans = 0

for i in S:
  if i in ok_list:
    ans += 1
  else:
    ans_list.append(ans)
    ans = 0

print(max(ans_list))

### FIXED CODE ###

S = input()

ok_list = ["A", "C", "G", "T"]
count = 0
ans = 0

for c in S:
  if c in ok_list:
    count += 1
    if ans < count:
      ans = count
  else:
    count = 0

print(ans)
s=[i for i in input()]
l=[]
cnt=0
for i in s:
  if i=="A" or i=="T" or i=="C" or i=="G" or i==" ":
    cnt+=1
    if i==(len(s)-1):
      l.append(cnt)
  else:
    l.append(cnt)
    cnt=0
print(max(l) if len(l)>1 else l[0])    

### FIXED CODE ###

s=[i for i in input()]
l=[]
cnt=0
for i in range(len(s)):
  if s[i]=="A" or s[i]=="T" or s[i]=="C" or s[i]=="G" or s[i]==" ":
    cnt+=1
    if i==len(s)-1:
      l.append(cnt)
  else:
    l.append(cnt)
    cnt=0  
print(max(l) if len(l)>1 else l[0])
N, T = input().split()
dic = {}
for i in range(int(input()):
	c, t = [int(i) in input().split()]
    dic[t].append(c)
if max(dic) <= T:
	print(dic[max(dic)])
else:
	print('TLE')

            


### FIXED CODE ###

N, T = map(int, input().split())
costs = []
for i in range(N):
    c, t = map(int, input().split())
    if t <= T:
        costs.append(c)
if len(costs) == 0:
    print('TLE')
else:
    print(min(costs))
####################################### Define
maxN = int(2e5 + 100)
a = [0] * maxN
b = [0] * maxN
ans = [0] * maxN
####################################### Functions
def solve() :
    L = R = -1
    for i in range(1, n + 1) :
        if i > R :
            L = R = i
            while R + 1 <= 2 * n and a[i] ^ b[1] == a[R + 1] ^ b[R - L + 2]: R += 1
#            print(a[i] ^ b[1], a[R + 1] ^ b[R - L + 2], "\n")
            ans[i] = R - L + 1
        else :
            k = i - L
            if ans[k] < R - i + 1 : ans[i] = ans[k]
            else :
                L = i
                while R + 1 <= 2 * n and a[i] ^ b[1] == a[R + 1] ^ b[R - L + 2]: R += 1
                ans[i] = R - L + 1
####################################### Main
n = int(input())
inp = input().split()
for i in range(1, n + 1) : a[i] = int(inp[i - 1])
for i in range(n + 1, 2 * n + 1) : a[i] = a[i - n]
inp = input().split()
for i in range(1, n + 1) : b[i] = int(inp[i - 1])
for i in range(n + 1, 2 * n + 1) : b[i] = b[i - n]

solve()

for i in range(1, n + 1):
    if ans[i] >= n:
        print(i - 1, a[i] ^ b[1])


### FIXED CODE ###

####################################### Define
maxN = int(6e5 + 100)
a = [0] * maxN
b = [0] * maxN
ans = [0] * maxN
####################################### Functions
def solve() :
    L = R = 0
    for i in range(2, 3 * n + 1) :
        if i > R :
            L = R = i
            while R + 1 <= 3 * n and (a[i] ^ a[1]) == (a[R + 1] ^ a[R - L + 2]): R += 1
#            print(a[i] ^ a[1], a[R + 1] ^ b[R - L + 2], R, L, "\n")
            ans[i] = R - L + 1
        else :
            k = i - L + 1
            if ans[k] < R - i + 1 : ans[i] = ans[k]
            else :
                L = i
                while R + 1 <= 3 * n and (a[i] ^ a[1]) == (a[R + 1] ^ a[R - L + 2]): R += 1
                ans[i] = R - L + 1
####################################### Main
n = int(input())
inp = input().split()
for i in range(n + 1, 2 * n + 1) : a[i] = int(inp[i - n - 1])
for i in range(2 * n + 1, 3 * n + 1) : a[i] = a[i - n]
inp = input().split()
for i in range(1, n + 1) : a[i] = int(inp[i - 1])

solve()

for i in range(n + 1, 2 * n + 1):
    if ans[i] >= n:
        print(i - n - 1, (a[i] ^ a[1]))
W,H,x,y = map(int,input().split())

#print(W,H,x,y)
if x ==W/2 and y == H/2:
    area =  "{0:.6f}".format(float(x*H))
    print(area,1)
else:
    area ="{0:.6f}".format(float(min(W-x)*H,x*H))
    print(area,0)

### FIXED CODE ###

W,H,x,y = map(int,input().split())

#print(W,H,x,y)
area =  "{0:.6f}".format(float(W*H/2))
if x == W/2 and y == H/2:
    print(area,1)
else:
    print(area,0)
a=list(int(input()))
if a[0]=a[1]=a[2] or a[1]=a[2]=a[3]:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

a=list(input())
if a[0]==a[1]==a[2] or a[1]==a[2]==a[3]:
    print("Yes")
else:
    print("No")
s = list(input())
for i in range(len(s)):
   if s[i] == "A":
      i_tmp1= i
   elif s[i] == "Z" and i >= i_tmp1:
      i_tmp2  = i

print(i_tmp2-i_tmp1+1)

### FIXED CODE ###

S = input()
a = S.find('A')
z = S[::-1].find("Z")
print(len(S[a:-(1+z)])+1)
S = input()
T = input()
ansCnt = 0
for i in range(len(S)):
    for j in range(1, len(S) + 1):
        if S[-j] == T[-j]:
            continue
        elif j != len(S):
            for z in range(len(S) - j):
                if S[-j] == T[z]:
                    S = S[0:z] + S[-j] + S[z:-j] + S[-j + 1:]
                    continue

if S == T:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

S = input()
T = input()
ansCnt = 0
for i in range(len(S)):
    if S == T:
        break
    S = S[-1] + S[0:-1]
if S == T:
    print('Yes')
else:
    print('No')
n,m,x = map(int , input().split())

tax = [input() for i in range(m)]
alltax = len(tax)
atax = len(tax[:x])
btax = alltax-atax
if atax > btax:
    print(btax)
else:
    print(atax)

### FIXED CODE ###

N, M, X = map(int, input().split())
A = set(map(int, input().split()))

result = len(set(range(0,X))&A)
result = min(result, len(set(range(X,N))&A))

print(result)
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.special import perm
# from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

########

N, K = l_inpl()

def cmb(n, r):
    r = min(n - r, r)
    if r == 0: 
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

def per(n, r):
    if r == 0: 
        return 1
    return reduce(mul, range(n, n - r, -1))

red_space = N - K + 1

MOD = 1000000007
for i in range(1, K+1):
    ans = 1
    print(cmb(K-1, i-1)*cmb(red_space, i)% MOD)


### FIXED CODE ###

import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.special import perm
from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")
import scipy.misc as scm
########

N, K = l_inpl()

def cmb(n, r):
    r = min(n - r, r)
    if r == 0: 
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

def per(n, r):
    if r == 0: 
        return 1
    return reduce(mul, range(n, n - r, -1))

red_space = N - K + 1

MOD = 1000000007
for i in range(1, K+1):
    print(comb(K-1, i-1, 1)*comb(red_space, i, 1) % MOD)
#!/usr/bin/env python3
import sys
INF = float("inf")

# 無向グラフを仮定する。


class Graph(object):
    def __init__(self, N):
        self.E = [[] for _ in range(N)]

    def add_edge(self, edge):
        s, t = edge
        self.E[s].append(t)


def solve(N: int, A: "List[List[int]]"):
    a_head = [0]*N
    stack = list(range(N))
    next_stack = []
    day = -1
    flag = True
    g = Graph(N)

    while flag:
        day += 1
        g.E = [[] for _ in range(N)]
        flag = False

        for i in stack:
            h = a_head[i]
            if h == N-1:
                continue
            if i in g.E[A[i][h]-1]:
                a_head[i] += 1
                a_head[A[i][h]-1] += 1
                flag = True
                next_stack.append(i)
                next_stack.append(A[i][h]-1)
                g.E[A[i][h]-1].remove(i)
            else:
                g.add_edge([i, A[i][h]-1])
        stack = next_stack[:]

    for h in a_head:
        if h != N-1:
            print(-1)
            return
    print(day)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [[int(next(tokens)) for _ in range(N - 1)]
         for _ in range(N)]  # type: "List[List[int]]"
    solve(N, A)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(S: str, T: str):
    print(sum([s == t for s, t in zip(S, T)]))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)


if __name__ == '__main__':
    main()
N,K = int(input())
p = list(map(int, input().split(" ")))
cnt = 0
for i in range(N):
  if p[i]=="l" and i!=0:
    if p[i]==p[i-1]:
      cnt += 1
  elif p[i]=="r" and i!=N-1:
    if p[i]==p[i+1]:
      cnt += 1
cnt += 2*K
if cnt>=N:
  cnt = N-1
print(cnt)

### FIXED CODE ###

N,K = list(map(int, input().split(" ")))
p = input()
cnt = 0
for i in range(N):
  if p[i]=="L" and i!=0:
    if p[i]==p[i-1]:
      cnt += 1
  elif p[i]=="R" and i!=N-1:
    if p[i]==p[i+1]:
      cnt += 1
cnt += 2*K
if cnt>=N:
  cnt = N-1
print(cnt)
def ff(x,y,z):
    return(x**2+y**2+z**2+x*y+y*z+z*x)

n=int(input())
an = []
for i in range(1,50):
    for j in range(1,50):
        for k in range(1,50):
            wk=ff(i,j,k)
            if wk<n:
                an.append(wk)
            else:
                break
ann=set(an)
annn=sorted(ann)
wk =0
for i in range(1,n+1):
    if i ==annn[wk]:
        print(3)
        if wk+1>=len(annn):
            pass
        else:
            wk+=1
    else:
        print(0)

### FIXED CODE ###

def ff(x,y,z):
    return(x**2+y**2+z**2+x*y+y*z+z*x)

n=int(input())
an=[0]*n
for i in range(1,100):
    for j in range(1,100):
        for k in range(1,100):
            wk=ff(i,j,k)
            if wk<=n:
                an[wk-1]+=1
for i in an:
    print(i)
import sys
print(len(str(sum(map(int,s.split())))))　for s in sys.stdin

### FIXED CODE ###

import sys
for s in sys.stdin:print len(str(sum(map(int,s.split()))))
n=int(input())
d,x=map(int,input().split())
print(sum(d//(int(input()+1) for _ in range(n))))

### FIXED CODE ###

n=int(input())
d,x=map(int,input().split())
ans=x+n
for _ in range(n):
  ans+=(d-1)//int(input())
print(ans)
N, A, B = map(int, input().split())

C = (N // (A + B)) + 1
S = ''
for i in range(C):
  S += 'b'*A + 'r'*B
  
print(S[:N].count('b'))

### FIXED CODE ###

N, A, B = map(int, input().split())

c1 = (N // (A + B))

c2 = (N % (A + B))
c3 = A if c2 > A else c2

print(c1*A + c3)
import sys
sys.setrecursionlimit(10**5)
x = int(input())

def mody(x,n):
	if n == 1:
		return 1
	if x%n == 0:
		return x
	else:
		return mody(x,n-1)

for i in range(0,10**5-x):
	n = mody(x+i,x+i-1)
	if n == 1:
		ans = x+i
		break
print(ans)

### FIXED CODE ###

def is_prime(x):
    if x<= 1: return False
    i=2
    while i*i<=x:
        if x%i==0:
            return False
        i+=1
    return True

ans = int(input())
while not is_prime(ans):
    ans+=1
print(ans)
while True:
    c =0
    a = int(input())
    me = 1000 -a
    while me != 0:
     if me >= 500:
        me -= 500 
        c +=1 
     elif me >= 100:
        me -= 100 
        c +=1
     elif me >= 50:
        me -= 50
        c+=1
     elif me >= 10:
        me -= 10
        c +=1
     elif me >= 5:
        me -= 5
        c +=1
     elif me >= 1:
        me -= 1
        c+=1
       
       
     
     
    print c

### FIXED CODE ###

while True:
  c =0
  a = int(input())
  if a == 0:break
  else:
    me = 1000 -a
    while me != 0:
     if me >= 500:
        me -= 500 
        c +=1 
     elif me >= 100:
        me -= 100 
        c +=1
     elif me >= 50:
        me -= 50
        c+=1
     elif me >= 10:
        me -= 10
        c +=1
     elif me >= 5:
        me -= 5
        c +=1
     elif me >= 1:
        me -= 1
        c+=1
       
       
     
     
    print c
n = int(input())
if n ==1:
    print('Hello world')
if n ==2:
    a,b = map(int,input().split())
    print(a+b)

### FIXED CODE ###

n = int(input())
if n ==1:
    print('Hello World')
if n ==2:
    a = int(input())
    b = int(input())
    ans = a+b
    print(ans)
def isPal(s):
    if s == s[::-1]:
        return True
    return False

s = list(input())
pal = ''
for ch in s:
    if ch != 'x':
        pal+=ch

if not isPal(pal):
    print(-1)
else:
    beg = s.index(pal[0])
    end = len(s)-1 - s[::-1].index(pal[-1])
    half = 0 if len(pal) == 1 else len(pal)//2 + 1
    cnt = 0
    for i in range(len(s)):
        if cnt == half:
            break
        if s[i] != 'x':
            cnt += 1
    print(abs(cnt-beg - (end-cnt)) + abs(beg - (len(s)-1-end)))

    
    


### FIXED CODE ###

s = list(input())
l = 0
r = len(s)-1
ans = 0
while l < r:
    if s[l] == s[r]:
        l+=1
        r-=1
    elif s[l] == 'x':
        l+=1
        ans+=1
    elif s[r] == 'x':
        r-=1
        ans+=1
    else:
        print(-1)
        exit()
print(ans)
N = int(input())
A = list(map(int, input().split()))
B = [0]
t = 0
for i in range(N):
    B.append(B[i] + A[i])
 
C = set(B)
for j in C:
    z = B.count(j)
    if count > 1:
        t += z*(z-1)/2
 
print(int(t))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = {}
t = 0
x = 0
B[0] = 1
for i in A:
    x += i
    t += B.get(x, 0)
    B[x] = B.get(x, 0) + 1

print(t)
# coding: utf-8

a, b = map(int, raw_input().split())

ans = 1

for i in range(a, b+1):
  ans *= i

if ans > 0:
  print "Positive"

elif ans == 0:
  print "Zero" #Fate/Zeroは神アニメ

else:
  print "Negative"

### FIXED CODE ###

# coding: utf-8

a, b = map(int, raw_input().split())

if a > 0:
  print "Positive"

elif b >= 0:
  print "Zero" #Fate/Zeroは神アニメ

else:

  if (b - a) % 2 == 0:
    print "Negative"

  else:
    print "Positive"
n = input()
a = input()
j = n % 500
if (j <= a):
  print("YES")
else:
  print("NO")

### FIXED CODE ###

n = int(input())
a = int(input())
j = n % 500
if (j <= a):
  print("Yes")
else:
  print("No")
n, k  = map(int, input().split())
an = list(map(int, input().split()))
bn = [-1]*(n+1)

now=1
bn[1]=0
for i in range(1, k+1):
    print(bn)
    now = an[now-1]
    if bn[now] >0:
        rp =i-bn[now]
        p= (k-i)%rp
        for j in range(p):
            now = an[now-1]
        print(now)
        exit(0)
    bn[now]=i
print(now)

### FIXED CODE ###

n, k  = map(int, input().split())
an = list(map(int, input().split()))
bn = [-1]*(n+1)

now=1
bn[1]=0
for i in range(1, k+1):
 #   print(bn)
    now = an[now-1]
    if bn[now] >0:
        rp =i-bn[now]
        p= (k-i)%rp
        for j in range(p):
            now = an[now-1]
        print(now)
        exit(0)
    bn[now]=i
print(now)