Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

def yakusu(x):
    ans=[1]
    check=2
    while(x!=1):
        if(x%check==0):
            ans+=[check]
            while(x%check==0):
                x=x//check
        check+=1  
    return ans
def main():
    a,b = map(int,input().split())	
    ans=0
    y1=yakusu(a)
    for i in y1:
        if b%i==0:
            ans+=1
    print(ans)

main()



### FIXED CODE ###

def yakusu(x):
    ans=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            ans.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      ans.append(x)
    return ans
def main():
    a,b = map(int,input().split())	
    ans=0
    y1=yakusu(a)
    for i in y1:
        if b%i==0:
            ans+=1
    print(ans)
 
main()
### BUGGY CODE ###

from collections import Counter

def main():
    N, *A = map(int, open(0).read().split())

    ctr = Counter(A)
    memo = set()
    ans = 0

    for a in sorted(A):
        if ctr[a] == 1:
            if a == 1:
                ans = 1
                break

            for i in range(1, int(a ** 0.5) + 1):
                if a % i == 0:
                    if (i in memo) or (a // i in memo):
                        break
            else:
                ans += 1

        memo.add(a)

    print(ans)

    
if __name__ == "__main__":
    main()
    

### FIXED CODE ###

from collections import Counter

N, *A = map(int, open(0).read().split())

m = max(A) + 1
ok = [True] * m
ctr = Counter(A)
ans = 0
for a in sorted(A):
    if ok[a] and ctr[a] == 1:
        ans += 1
        
    for j in range(2 * a, m, a):
        ok[j] = False
            
print(ans)
### BUGGY CODE ###

N,K=map(int,input().split())
D=[0]*(K+1)
for i in range(1,K+1):
  a=K//i
  D[i]=a**N
for i in range(K//2,0,-1):
  a=K//i
  for j in range(1,a+1):
    if j!=1:
      D[i]-=D[i*j]
ans=0
for i in range(1,K+1):
  ans+=(i*D[i])%(10**9+7)
print(ans%(10**9+7))

### FIXED CODE ###

N,K=map(int,input().split())
D=[0]*(K+1)
ans=0
mod=10**9+7
for i in range(K,0,-1):
  D[i]=(pow(K//i,N,mod)-sum(D[i::i]))%mod
  ans+=(D[i]*i)%mod
  ans%=mod
print(ans)
### BUGGY CODE ###

import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))
    L = sorted(L)

    ans = 0

    for i in range(N):
        for j in range(i+1, N):
            X = L[i] + L[j]
            l = bisect.bisect_left(L, X, lo=j+1)
            ans += len(L[j+1:l])
            #print(L[j + 1:l])
    print(ans)
    return 0

if __name__ == '__main__':
    main()


### FIXED CODE ###

import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))
    L = sorted(L)

    ans = 0

    for i in range(N):
        for j in range(i+1, N):
            X = L[i] + L[j]
            l = bisect.bisect_left(L, X, lo=j+1)
            ans += (l-(j+1))
            #print(L[j + 1:l])
    print(ans)
    return 0

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import numpy as np
import collections

N = int(input())
A = list(map(int, input().split()))
ans = 10**18
dists_A2i = []

for i in range(1, N+1):
    dist_A2i = A[i-1] - i
    dists_A2i.append(dist_A2i)

c = collections.Counter(dists_A2i)

max_c_list = [key for key, value in c.items() if value == max(c.values())]

dists_A2i = np.array(dists_A2i)

for max_c in max_c_list:
    check_dists_A2i = abs(dists_A2i - max_c)
    ans = min(ans, sum(check_dists_A2i))

print(ans)

### FIXED CODE ###

import numpy as np
import collections

N = int(input())
A = list(map(int, input().split()))
ans = 0
dists_A2i = []

for i in range(1, N+1):
    dist_A2i = A[i-1] - i
    dists_A2i.append(dist_A2i)

dists_A2i = np.array(dists_A2i)
dists_median = np.median(dists_A2i)
dists_A2i = abs(dists_A2i - dists_median)
ans = sum(dists_A2i)
print(int(ans))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import unittest
import math

MOD = 10**9+7


def func(n,m):
    fac = [1 for _ in range(n+100)]
    finv = [1 for _ in range(n+100)]
    inv = [1 for _ in range(n+100)]
    for i in range(2,n+100):
        fac[i] = (fac[i-1]*i)%MOD
        inv[i] = (MOD - inv[MOD%i] * (MOD//i))%MOD
        finv[i] = (finv[i-1]*inv[i])%MOD

    def comb(a,b):
        return (fac[a]*((finv[b]*finv[a-b])%MOD))%MOD

    fact = {}
    for x in range(2, m+1):
        while m%x==0:
            if x not in fact:
                fact[x] = 0
            fact[x] += 1
            m = m//x
        if m==1:
            break

    ret = 1
    for k in fact.values():
        ret *= comb(k+n-1,k)
        ret %= MOD
    return ret

class Test(unittest.TestCase):
    def test(self):
        self.assertEqual(func(2,6), 4)
        self.assertEqual(func(3,12), 18)
        self.assertEqual(func(100000, 1000000000), 957870001)
        self.assertEqual(func(2,3), 2)

if __name__ == '__main__':
    n,m = map(int, input().split())
    print(func(n,m))
    # unittest.main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import unittest
import math

MOD = 10**9+7


def func(n,m):
    fac = [1 for _ in range(n+100)]
    finv = [1 for _ in range(n+100)]
    inv = [1 for _ in range(n+100)]
    for i in range(2,n+100):
        fac[i] = (fac[i-1]*i)%MOD
        inv[i] = (MOD - inv[MOD%i] * (MOD//i))%MOD
        finv[i] = (finv[i-1]*inv[i])%MOD

    def comb(a,b):
        return (fac[a]*((finv[b]*finv[a-b])%MOD))%MOD

    fact = {}
    for x in range(2, math.ceil(math.sqrt(m))+1):
        while m%x==0:
            if x not in fact:
                fact[x] = 0
            fact[x] += 1
            m = m//x
        if m==1:
            break
    if m!=1:
        fact[m] = 1

    ret = 1
    for k in fact.values():
        ret *= comb(k+n-1,k)
        ret %= MOD
    return ret

class Test(unittest.TestCase):
    def test(self):
        self.assertEqual(func(2,6), 4)
        self.assertEqual(func(3,12), 18)
        self.assertEqual(func(100000, 1000000000), 957870001)
        self.assertEqual(func(2,3), 2)

if __name__ == '__main__':
    n,m = map(int, input().split())
    print(func(n,m))
    # unittest.main()
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
score = 1
for j in range(k):
    score *= a[j]

for i in range(n - k):
    score2 = score / a[i] * a[k + i]
    if score2 > score:
        print("Yes")
    else:
        print("No")
    score = score2


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n - k):
    if a[k+i] > a[i]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
l = []
if m<=n:
    print(0)
else:
    for i in range(0, m-1):
        l.append(x[i+1]-x[i])
#   l.sort(reverse=True)
    for j in range(n-1):
        l.remove(max(l))
    print(sum(l))


### FIXED CODE ###

n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
l = []
if m<=n:
    print(0)
else:
    for i in range(0, m-1):
        l.append(x[i+1]-x[i])
    l.sort(reverse=True)
    for j in range(n-1):
        del l[0]
    print(sum(l))
### BUGGY CODE ###

import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
# MOD = 10 ** 9 + 7
MOD = 998244353


def main():
    N, K = map(int, readline().split())
    S = set()
    for k in range(K):
        L, R = map(int, readline().split())
        S |= set(range(L, R + 1))

    dp = [0] * (N + 20)
    dp[1] = 1
    S = list(S)

    for i in range(1, N + 5):
        for s in S:
            if i - s > 0:
                dp[i] += dp[i - s] % MOD
                dp[i] %= MOD
    print(dp[N])


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
M = 998244353


class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele
        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res


def segfunc(x, y):
    return x + y


def main():
    N, K = map(int, readline().split())
    LR = list(list(map(int, readline().split())) for _ in range(K))
    LR.sort()

    A = [0] * (N + 1)
    A[1] = 1
    seg = SegTree(A, segfunc=segfunc, ide_ele=0)
    for i in range(2, N + 1):
        for l, r in LR:
            if i - l > 0:
                total = (seg.tree[i + seg.num] + seg.query(max(1, i - r), min(N, i - l + 1)) % M)
                seg.update(i, total)
            else:
                break
    print(seg.tree[seg.num + N] % M)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(m):
    b, c = map(int, input().split())
    for i in range(b):
        A.append(c)

A = sorted(A, reverse=True)
result = [A[i] for i in range(n)]
print(sum(result))

### FIXED CODE ###

import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))
### BUGGY CODE ###

a=int(input())
b=0
while a>0 or b==0:
  if a%10==7:
    b=1
  a/=10
  
if b==1:
  print("Yes")
else:
  print("No")
  

### FIXED CODE ###

a=input()

if a[0]=='7' or a[1]=='7' or a[2]=='7':
  print("Yes")
else:
  print("No")
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, T = map(int, readline().split())

AB= list(map(int, read().split()))
A = AB[0::2]
B = AB[1::2]
ls = sorted(zip(A, B))
#ls = list(zip(A, B))
# 食べるのにかかる時間で昇順にソート
#ls.sort()
# 上の並び順において、ls[i:]の美味しさの最大値をdeli[i]とする
deli = [0]*N
deli[- 1] = ls[-1][- 1]
for i in range(N - 2, 0, - 1):
    deli[i] = max(deli[i + 1], ls[i][- 1])

res = 0
dp = [0]*T
for i in range(N - 1):
    for j in range(T - 1, ls[i][0] - 1, - 1):
        dp[j] = max(dp[j], dp[j - ls[i][0]] + ls[i][1])
    res = max(res, dp[- 1] + deli[i + 1])
print(res)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, T = map(int, readline().split())

AB= list(map(int, read().split()))
A = AB[0::2]
B = AB[1::2]
ls = list(zip(A, B))
# 食べるのにかかる時間で昇順にソート
ls.sort()
# 上の並び順において、ls[i:]の美味しさの最大値をdeli[i]とする
deli = [0]*N
deli[- 1] = ls[-1][- 1]
for i in range(N - 2, - 1, - 1):
    deli[i] = max(deli[i - 1], ls[i][- 1])

res = 0
dp = [0]*T
for i in range(N - 1):
    for j in range(T - 1, - 1, - 1):
        if ls[i][0] <= j:
            dp[j] = max(dp[j], dp[j - ls[i][0]] + ls[i][1])
    res = max(res, dp[- 1] + deli[i + 1])
print(res)
### BUGGY CODE ###

N = int(input())
H = list(map(int, input().split()))

max_h = -1
for i in range(0, N):
    h = 0
    for j in range(i, N-1):
        if H[j] >= H[j+1]:
            h += 1
        else:
            break
    if h > max_h:
        max_h = h
print(max_h)

### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))

max_h = -1
h = 0
for i in range(0, N-1):
    if H[i] >= H[i+1]:
        h += 1
    else:
        if h > max_h:
            max_h = h
        h = 0
if h > max_h:
    max_h = h
print(max_h)
### BUGGY CODE ###

from collections import deque
import copy
H,W=map(int, input().split())
A=[]
d=deque()
for h in range(H):
  a=[]
  s=input()
  for w in range(W):
    if s[w]=='.':
      a.append(-1)
    else:
      a.append(0)
      d.append((h,w))
  A.append(a)
cnt=1
DIF=[(1,0),(0,1),(-1,0),(0,-1)]
tmp=deque()
while d:
  point=d.popleft()
  for dif in DIF:
    x=point[0]+dif[0]
    y=point[1]+dif[1]
    if 0<=x<H and 0<=y<W and A[x][y]==-1:
      tmp.append((x,y))
      A[x][y]=cnt
  if not d:
    #print(tmp)
    d=copy.deepcopy(tmp)
    tmp=deque()
    #print(d)
    cnt+=1
ans=0    
for h in range(H):
  Amax=max(A[h])
  ans=max(ans,Amax)
#print(A)
print(ans)

### FIXED CODE ###

H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))
### BUGGY CODE ###

n = int(input())
a = ["" for i in range(n)]
for i in range(n):
	a[i] = int(input())

a_sort = sorted(a)
for i in range(n):
	if max(a) == a[i]:
		print(a_sort[-2])
	else:
		print(max(a))


### FIXED CODE ###

n = int(input())
a = ["" for i in range(n)]
for i in range(n):
	a[i] = int(input())

a_sort = sorted(a)
max = a_sort[-1]
second = a_sort[-2]

for i in range(n):
	if a[i] == max:
		print(second)
	else:
		print(max)
### BUGGY CODE ###

from functools import reduce
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))


lcm = A[0]
for i in range(1, N):
    lcm = lcm * A[i] // gcd(lcm, A[i])

MOD = 10 ** 9 + 7
ans = 0
for i, a in enumerate(A):
    ans += lcm // a
    ans %= MOD

print(ans)


### FIXED CODE ###

from functools import reduce
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))


lcm = A[0]
for a in A[1:]:
    lcm = lcm * a // gcd(lcm, a)


MOD = 10 ** 9 + 7
lcm %= MOD
ans = 0
for a in A:
    ans += lcm * pow(a, MOD-2, MOD)
    ans %= MOD

print(ans)
### BUGGY CODE ###

def resolve():
    N = int(input())
    A = []
    for _ in range(N):
        _a = list(map(lambda x: int(x)-1, input().split()))
        A.append(_a)
    ptrs = [0 for _ in range(N)]
    day = 0
    players = set([i for i in range(N)])
    finished = set()
    loops = 0
    while loops < 10**5:
        todays_players = set()
        matched = False
        if len(finished) == N:
            break
        #print("------")
        for home in (players-finished):
            if home in finished:
                continue
            away = A[home][ptrs[home]]
            if away in finished:
                continue
            #print(home, away)
            away_opp = A[away][ptrs[away]]
            if home in todays_players or away in todays_players:
                continue
            if home == away_opp:
                ptrs[home] += 1
                ptrs[away] += 1
                todays_players.add(home)
                todays_players.add(away)
                matched = True
                if ptrs[home] == N-1:
                    finished.add(home)
                if ptrs[away] == N-1:
                    finished.add(away)
        #print(ptrs)
        if matched:
            day += 1
        else:
            day = -1
            break
        loops += 1
    assert loops < 10**5, "error"
    print(day)





if '__main__' == __name__:
    resolve()


### FIXED CODE ###

def resolve():
    N = int(input())
    A = []
    for _ in range(N):
        _a = list(map(lambda x: int(x)-1, input().split()))
        A.append(_a)
    ptrs = [0 for _ in range(N)]
    day = 0
    players = set([i for i in range(N)])
    finished = set()
    yest_players = set([i for i in range(N)])
    while True:
        todays_players = set()
        matched = False
        if len(finished) == N:
            break
        #print("------")
        for home in yest_players:
            if home in finished:
                continue
            away = A[home][ptrs[home]]
            if away in finished:
                continue
            #print(home, away)
            away_opp = A[away][ptrs[away]]
            if home in todays_players or away in todays_players:
                continue
            if home == away_opp:
                ptrs[home] += 1
                ptrs[away] += 1
                todays_players.add(home)
                todays_players.add(away)
                matched = True
                if ptrs[home] == N-1:
                    finished.add(home)
                if ptrs[away] == N-1:
                    finished.add(away)
        yest_players = todays_players
        #print(ptrs)
        if matched:
            day += 1
        else:
            day = -1
            break
    print(day)





if '__main__' == __name__:
    resolve()
### BUGGY CODE ###

n = int(input())
new_s = input()
# new_s = ""
# for i in range(len(s)):
#    if i<3:
#        new_s+=s[i]
#     else:
#         if s[i-1] == s[i] and s[i-2] == s[i]:
#             pass
#         else:
#             new_s+=s[i]
pas = -1
ans = 0
lens = len(new_s)
for i in range(1000):
    ott = 0
    pas = int(pas)+1
    if pas < 10:
        pas = "00"+str(pas)
    elif pas < 100:
        pas = "0"+str(pas)
    pas = str(pas)
    idx = -1
    while idx < lens-1:
        idx += 1
        if ott == 0:
            if pas[0] == new_s[idx]:
                ott += 1
        elif ott == 1:
            if pas[1] == new_s[idx]:
                ott += 1
        elif ott == 2:
            if pas[2] == new_s[idx]:
                ott += 1
                ans += 1
        if ott == 3:
            break
print(ans)



### FIXED CODE ###

n = int(input())
new_s = input()
pas = -1

ans = 0
lens = len(new_s)
for i in range(1000):
    ott = 0
    pas = int(pas)+1
    if pas < 10:
        pas = "00"+str(pas)
    elif pas < 100:
        pas = "0"+str(pas)
    pas = str(pas)
    idx = -1
    while idx < lens-1:
        idx += 1
        if ott == 0:
            if pas[0] == new_s[idx]:
                ott += 1
        elif ott == 1:
            if pas[1] == new_s[idx]:
                ott += 1
        elif ott == 2:
            if pas[2] == new_s[idx]:
                ott += 1
                ans += 1
        if ott == 3:
            break
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
Q = int(input())
numberlist = [0 for i in range(100001)]
prime = [2]

for i in range(3, 100001, 2):
    flag = 1
    for j in prime:
        if i % j == 0:
            flag = 0
            break
    if flag == 1:
        prime.append(i)

for i in prime:
    if (i+1)//2 in prime:
        numberlist[i] += 1
for i in range(100000):
    numberlist[i+1] += numberlist[i]


for i in range(Q):
    l, r = map(int, input().split())
    print(numberlist[r]-numberlist[l-1])


### FIXED CODE ###

Q = int(input())
numberlist = [0 for i in range(100001)]
prime = [2]

for i in range(3, 100001, 2):
    flag = 1
    for j in prime:
        if i % j == 0:
            flag = 0
            break
    if flag == 1:
        prime.append(i)

for i in prime:
    if (i+1)//2 in prime:
        numberlist[i] += 1
for i in range(100000):
    numberlist[i+1] += numberlist[i]


for i in range(Q):
    l, r = map(int, input().split())
    print(numberlist[r]-numberlist[l-1])
### BUGGY CODE ###

def f(c):
    return ord(c) - ord("A")


def main():
    s = list(map(f, input()))
    ln = len(s)

    abc = [0, 1, 2]
    bca = [1, 2, 0]

    ans = 0
    for i in range(ln - 2):
        if s[i:i+3] == abc:
            s[i:i+3] = bca
            ans += 1
            j = i - 1
            while j >= 0 and s[j:j+3] == abc:
                s[j:j+3] = bca
                ans += 1
                j -= 1
            i += 1

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

s = input()

s = s.replace("BC", "D")

ans = 0
a_cnt = 0
for e in s:
    if e == "A":
        a_cnt += 1

    elif e == "D":
        ans += a_cnt

    else:
        a_cnt = 0

print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
ans = 1
for i in range(N):
    ans = ans*A[i]
if ans > 10**18:
    print(-1)
else:
    print(int(ans))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
U = 10 ** 18
p = 1
for x in A:
    p *= x
    if p > U:
        p = U + 1
 
if p > U:
    print(-1)
else:
    print(p)
### BUGGY CODE ###

s = input()
k = int(input())
lst=[]
ls=len(s)
for i in range(ls):
    for j in range(i+1,ls+1):
        lst.append(s[i:j])
lst=sorted(set(lst))
print(lst[k-1])

### FIXED CODE ###

s = input()
k = int(input())
lst=[]
ls=len(s)
for i in range(ls):
    for j in range(i+1,min(ls+1,i+k+1)):
        lst.append(s[i:j])
lst=sorted(set(lst))
print(lst[k-1])
### BUGGY CODE ###

q = int(input())

n = 10**5+1
nums = [True]*n
nums[1] = False
for i in range(4, n, 2): nums[i] = False
for i in range(3, int(n**0.5)+1, 2):
  if nums[i]:
    for j in range(i+i, n, i): nums[j] = False

for _ in range(q):
  ans = 0
  l,r = map(int, input().split())
  for i in range(l, r+1):
    if i%2 == 1:
      if nums[i] and nums[(i+1)//2]: ans += 1
  print(ans)

### FIXED CODE ###

q = int(input())

n = 10**5+1
flag = [True]*n
flag[1] = False
for i in range(4, n, 2): flag[i] = False
for i in range(3, int(n**0.5)+1, 2):
  if flag[i]:
    for j in range(i+i, n, i): flag[j] = False

nums = [0]*n
for i in range(1,n):
  if i%2 == 1:
    if flag[i] and flag[(i+1)//2]: nums[i] = nums[i-1]+1
    else: nums[i] = nums[i-1]
  else: nums[i] = nums[i-1]

for _ in range(q):
  l,r = map(int, input().split())
  print(nums[r]-nums[l-1])
### BUGGY CODE ###

a, b, m = map(int, input().split())
ref = list(map(int, input().split()))
micro = list(map(int, input().split()))
tk = [list(map(int, input().split())) for i in range(m)]

mini = 10 ** 6
for i in range(a):
    for j in range(b):
        if ref[i] + micro[j] < mini:
            mini = ref[i] + micro[j]

amount = 10 ** 6
for i in tk:
    if ref[i[0]-1] + micro[i[1]-1] - i[2] < amount:
        amount = ref[i[0]-1] + micro[i[1]-1] - i[2]

print(min(mini, amount))

### FIXED CODE ###

a, b, m = map(int, input().split())
ref = list(map(int, input().split()))
micro = list(map(int, input().split()))
tk = [list(map(int, input().split())) for i in range(m)]

mini = min(ref) + min(micro)

amount = 10 ** 6
for i in tk:
    if ref[i[0]-1] + micro[i[1]-1] - i[2] < amount:
        amount = ref[i[0]-1] + micro[i[1]-1] - i[2]

print(min(mini, amount))
### BUGGY CODE ###

def D():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    next = a[0]
    path = [0]
    while not next in path:
        k -= 1
        if k==0:
            print(next)    
            break
        path.append(next)
        next = a[next - 1]
    if k!=0:
        cyclic = path[path.index(next):]
        print(cyclic[k%(len(cyclic))-1])

D()

### FIXED CODE ###

def D():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    next = a[0]
    path = [1]
    visited = [True] + [False]*(n-1)
    while not visited[next-1]:
        k -= 1
        if k==0:
            print(next)    
            break
        path.append(next)
        visited[next-1] = True 
        next = a[next-1]
    if k!=0:
        cyclic = path[path.index(next):]
        print(cyclic[k%(len(cyclic))-1])

D()