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

K = int(input())
ans = -1
keep = 0

for i in range(K):
    keep = (keep + 7 * 10 ** i) % K
    if keep == 0:
        ans = i + 1
        break
print(ans)

### FIXED CODE ###

K = int(input())
ans = -1
keep = 0
check = 7
for i in range(K):
    keep = (keep + check) % K
    if keep == 0:
        ans = i + 1
        break
    check = (check * 10) % K
print(ans)
### BUGGY CODE ###

import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint=====================================
N, K = map(int, input().split())
N, M = map(int, input().split())
A, B = map(int, input().split())

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

L, R = map(int, input().split())

1行のstring=================================
S, T = input().split()

1行の整数配列================================
P = list(map(int,input().split()))

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
D = list(map(int,input().split()))

L = list(map(int,input().split()))
R = list(map(int,input().split()))

T = list(map(int,input().split()))

改行あり整数==================================
X = []
Y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    X.append(x1)
    Y.append(y1)

A = []
for i in range(N):
    a=int(input())
    A.append(a)

Pair = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    Pair.append((x1, y1))
    
2次元整数配列=====================================
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    A.append(tmp)


N行M列の初期化====================================
dp = [[VAL] * RETU for i in range(GYO)]

'''

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

common = 1
for a in A:
    common = common * a // math.gcd(common, a)

ans = 0
for a in A:
    ans += common // a
    ans %= MOD

print(ans)




### FIXED CODE ###

import sys
sys.setrecursionlimit(4100000)
import math




N = int(input())


import fractions
a = list(map(int, input().split()))
koubai = a[0]
small = []
for i in range(0, N//2):
    small.append(a[2*i + 1] * a[2*i] // fractions.gcd(a[2*i + 1], a[2*i]))

small.append(a[-1])
for i in range(len(small)):
    koubai = koubai * small[i] // fractions.gcd(koubai, small[i])


ans = int(0)
for i in range(N):
    ans += koubai // a[i]
    
ans %= 1000000007

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

# -*- coding: utf-8 -*-

import sys
from math import factorial

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD

N = INT()
A = LIST()
B = [0] + [A[i+1] - A[i] for i in range(N-1)]

add = factorial(N-1) % MOD
cnt = [0] * N
for i in range(1, N):
    cnt[i] = round(cnt[i-1] + add)
    cnt[i] %= MOD
    add *= fermat(i , (i+1), MOD)

ans = 0
for i in range(1, N):
    ans += B[i] * cnt[i]
    ans %= MOD
print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class ModTools:
    """ 階乗たくさん使う時用のテーブル準備 """

    def __init__(self, MAX, MOD):
        """ MAX：階乗に使う数値の最大以上まで作る """
        
        MAX += 1
        self.MAX = MAX
        self.MOD = MOD
        # 階乗テーブル
        factorial = [1] * MAX
        factorial[0] = factorial[1] = 1
        for i in range(2, MAX):
            factorial[i] = factorial[i-1] * i % MOD
        # 階乗の逆元テーブル
        inverse = [1] * MAX
        # powに第三引数入れると冪乗のmod付計算を高速にやってくれる
        inverse[MAX-1] = pow(factorial[MAX-1], MOD-2, MOD)
        for i in range(MAX-2, 0, -1):
            # 最後から戻っていくこのループならMAX回powするより処理が速い
            inverse[i] = inverse[i+1] * (i+1) % MOD
        self.fact = factorial
        self.inv = inverse

    def div(self, x, y):
        """ MOD除算 """

        return x * pow(y, self.MOD-2, self.MOD) % self.MOD

N = INT()
A = LIST()
B = [0] + [A[i+1] - A[i] for i in range(N-1)]

mt = ModTools(N, MOD)
add = mt.fact[N-1]
cnt = [0] * N
for i in range(1, N):
    cnt[i] = round(cnt[i-1] + add)
    cnt[i] %= MOD
    add *= mt.div(i , (i+1))
    add %= MOD

ans = 0
for i in range(1, N):
    ans += B[i] * cnt[i]
    ans %= MOD
print(ans)
### BUGGY CODE ###

# import numpy as np

N,M=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(N)]
A.sort()

# A = np.array(A)

cnt = 0

for day in range(1,M+1):
    B = [x[1] for x in A if x[0]<=day]
    if B:
        ind = B.index(max(B))
        cnt += B[ind]
        del A[ind]
print(cnt)


### FIXED CODE ###

from heapq import*
(N,M),*t=[map(int,s.split())for s in open(0)]
q=[0]*10**5
v=[[]for _ in q]
z=0
for a,b in t:v[a-1]+=[b]
for i in v[:M]:
	for j in i:heappush(q,-j)
	z-=heappop(q)
print(z)
### BUGGY CODE ###

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

cnt = 0
for _ in range(a, b + 1):
    if _ % x == 0:
        cnt += 1
print(cnt)


### FIXED CODE ###

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

print(b // x - (a - 1) // x)
### BUGGY CODE ###

#C
L, R = list(map(int, input().split()))
if (R - L) == 2019:
    result = 0
else:
    result = 2018
    for i in range(L,R+1):
        for s in range(i+1,R+1):
            x = (i*s)%2019
            if x == 0:
                result = 0
            elif result > x:
                result = x
print(result)

### FIXED CODE ###

#C
import sys
L, R = list(map(int, input().split()))
if (R - L) == 2019:
    result = 0
else:
    result = 2018
    for i in range(L,R+1):
        for s in range(i+1,R+1):
            x = (i*s)%2019
            if x == 0:
                result = 0
                print(0)
                sys.exit()
            elif result > x:
                result = x
print(result)
### BUGGY CODE ###

S=list(map(int,list(input())))
N=len(S)

remainder=[0]*2019
val=0
for i in range(1,N+1):
  val+=S[-i]*(10**(i-1))
  remainder[val%2019]+=1

ans=remainder[0]
for i in range(2019):
  if remainder[i]<=1:
    continue
  else:
    ans+=remainder[i]*(remainder[i]-1)//2
print(ans)

### FIXED CODE ###

S=input()
N=len(S)
M=2019

remainder=[0]*M
val=0
for i in range(N):
  val=(int(S[N-1-i])*pow(10,i,M)+val)%M
  remainder[val]+=1

ans=remainder[0]
for i in range(2019):
  ans+=remainder[i]*(remainder[i]-1)//2
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
arr = [int(x) for x in input().split()]
Max = 3005

dp = [[0 for i in range(n)] for i in range(n)]

for l in range(n-1,-1,-1):
    for r in range(l, n):
        if l == r:
            dp[l][r] = arr[l]
        else:
            dp[l][r] = max(arr[l] - dp[l+1][r], arr[r] - dp[l][r-1])

print(dp[0][n-1])

### FIXED CODE ###

def deque(n, arr):
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = arr[i]

    for l in range(n-2, -1, -1):
        for r in range(l+1, n):
            L = arr[l] - dp[l+1][r]
            R = arr[r] - dp[l][r-1]
            dp[l][r] = L if L > R else R
    return dp[0][n-1]

n = int(input())
arr = [int(x) for x in input().split()]
print(deque(n, arr))
### BUGGY CODE ###

N=int(input())
for n in range(1,3501):
  for h in range(1,3501):
    a=N*n*h
    b=4*n*h-N*(n+h)
    if b>0 and a%b==0:
      w=a//b
      print(n,h,w)
      exit()

### FIXED CODE ###

N=int(input())
for n in range(1,3501):
  for h in range(1,3501):
    a=N*n*h
    b=4*n*h-N*(n+h)
    if b>0 and a%b==0:
      w=a//b
      print(n,h,w)
      exit()
### BUGGY CODE ###

# -*- coding:utf-8 -*-

def solve():
    K = int(input())
    a = 7%K
    i = 1
    Kset = set()
    Kset.add(a)
    while a!=0:
        a = (a*10+7)%K
        i += 1
        if a in Kset:
            print(-1)
            return
    print(i)


if __name__ == "__main__":
    solve()


### FIXED CODE ###

# -*- coding:utf-8 -*-

def solve():
    K = int(input())
    a = 7%K
    i = 1
    Kset = set()
    Kset.add(a)
    while a!=0:
        a = (a*10+7)%K
        i += 1
        if a in Kset:
            print(-1)
            return
        Kset.add(a)
    print(i)


if __name__ == "__main__":
    solve()
### BUGGY CODE ###

s="o"+input()+"o"
#o<<>>><>>o
ans=0
for i in range(0,len(s)-1):
  g=0
  for j in range(i,-1,-1):
    if s[j]=="<":
      g+=1
    else:
      break
  l=0
  for j in range(i+1,len(s)):
    if s[j]==">":
      l+=1
    else:
      break
  ans+=max(g,l)
print(ans)
  

### FIXED CODE ###

s=input()
#<<>>><>>

g=[0 for i in range(len(s)+1)]
l=[0 for i in range(len(s)+1)]

for i in range(len(s)):
  if s[i]=="<":
    g[i+1]=g[i]+1

for i in range(len(s)-1,-1,-1):
  if s[i]==">":
    l[i]=l[i+1]+1
    
ans=0
for i in range(len(s)+1):
  ans+=max(g[i],l[i])

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

inp = [input() for i in range(2)]
N = int(inp[0])
A = inp[1].split()
A = [int(i) for i in A]

for k in range(N):
    counter = 0
    A_k = A[k]
    other = A[:k] + A[k+1:]
    for i in range(N-2):
        for j in range(i+1, N-1):
            if other[i] == other[j]:
                counter += 1
    
    print(counter)


### FIXED CODE ###

import math
inp = [input() for i in range(2)]
N = int(inp[0])
A = list(map(int, inp[1].split()))
# B = 0
d = {}
for k in A:
    # a = A.count(k)
    # B += (a - 1) / 2
    if k in d.keys():
        d[k] += 1
    else:
        d[k] = 1

# for k in range(N):
#     c = A.count(A[k]) - 1
#     counter = B - c
#     print(int(counter))

p = {}
for k in d.keys():
    cnt = d[k]
    p[k] = cnt * (cnt-1) / 2

total = sum(p.values())

for item in A:
    print(int(total - d[item] + 1))
### BUGGY CODE ###

def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    else:
        return gcd(a, b % a)

# N = int(input())
A, B = [int(_) for _ in input().split()]

gcd_ab = gcd(A, B)
cds = []
for k in range(1, gcd_ab + 1):
    if gcd_ab % k == 0:
        cds.append(k)

ans = []
for cd in cds[1:]:
    for a in ans:
        if cd % a == 0:
            break
    else:
        ans.append(cd)

print(len(ans) + 1)


### FIXED CODE ###

import math
def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    else:
        return gcd(a, b % a)

# N = int(input())
A, B = [int(_) for _ in input().split()]

gcd_ab = gcd(A, B)
cds = []
for k in range(1, math.ceil(math.sqrt(gcd_ab)) + 1):
    if gcd_ab % k == 0:
        cds.append(k)
        cds.append(gcd_ab // k)
cds = list(set(cds))
cds.sort()

ans = []
for cd in cds[1:]:
    for a in ans:
        if cd % a == 0:
            break
    else:
        ans.append(cd)

print(len(ans) + 1)
### BUGGY CODE ###

import numpy as np
S = input()
list1 = []

for i in range(len(S)+1):
    for j in range(len(S)+1):
        if i<j:
            list1.append(int(S[i:j]))
arr = np.array(list1)%2019
print(np.sum(arr==0))     
  

### FIXED CODE ###

s = input()[::-1]
counts = [0] * 2019
counts[0] = 1
num, d = 0, 1
result = 0

for i in s:
    num += int(i) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1
    
for cnt in counts:
    result += cnt*(cnt-1)//2
    
print(result)
### BUGGY CODE ###

num = int(input())
numbers = input().split()
n =[]
sum = 1
for i in range(num):
  numbers[i] = int(numbers[i])
  sum = sum*numbers[i]
if (sum>10**18):
	print (-1)
else :
  	print (sum)

### FIXED CODE ###

num = int(input())
numbers = list(map(int,input().split()))
sum = 1
for i in range(num):
  sum *=numbers[i]
  if (sum>(10**18)):
    sum = -1
    break
if 0 in numbers:
  sum = 0
print (sum)
### BUGGY CODE ###

n, k = map(int, input().split())
s = set()
lr = []
for _ in range(k):
    # l, r = map(int, input().split())
    lr.append(tuple(map(int, input().split())))
    # for tmp in range(l, r+1):
    #     s.add(tmp)
mod = 998244353

# print(lr)
dp = [0]*n
dp[0] = 1

for i in range(1, n):
    for l, r in lr:
        for ss in range(l, r+1):
            if i-ss >= 0:
                dp[i] += dp[i-ss]
    dp[i] %= mod

print(dp[-1]%mod)

### FIXED CODE ###

n, k = map(int, input().split())
lr = []
for _ in range(k):
    lr.append(tuple(map(int, input().split())))
mod = 998244353

dp = [0]*n
dp[0] = 1

acc = [0]*n
acc[0] = 1

for i in range(1, n):
    for l, r in lr:
        if 0 <= i-r and i-l < i:
            dp[i] += acc[i-l]-acc[i-r-1]
        elif i-r < 0 and i-l < i:
            dp[i] += acc[i-l]
        elif i-r < 0 and i <= i-l:
            dp[i] += acc[i-1]
        elif 0 < i-r and i <= i-l:
            dp[i] += acc[i-1]-acc[i-r-1]
    acc[i] = acc[i-1]+dp[i]%mod

print(dp[-1]%mod)
### BUGGY CODE ###

import collections

n = int(input())
s = [input() for i in range(n)]

for i in range(n):
    s[i] = [s[i][j] for j in range(10)]
    s[i] = collections.Counter(s[i])

same =[]

for dic in s:
    count = 0
    while dic in s:
        s.remove(dic)
        count += 1
    else:
        same.append(count)

ans = 0

for num in same:
    ans += num * (num-1) // 2

print(ans)


### FIXED CODE ###

import collections
n = int(input())

s = ["".join(sorted(input())) for i in range(n)]

a = collections.Counter(s)

ans = 0

for i in a.values():
    ans += i*(i-1)//2

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

from collections import Counter

N = int(input())
S = list(input())

cnt = Counter(S)

ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] != S[j]) & (S[j] != S[k]) & (S[k] != S[i]) :
        ans -= 1

print(ans)

### FIXED CODE ###

from collections import Counter

N = int(input())
S = list(input())

cnt = Counter(S)

ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] == S[j]) or (S[j] == S[k]) or (S[k] == S[i]) :
        continue
      ans -= 1

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

n,m=map(int,input().split())
an=[1]*n
for i in range(m):
    l,r=map(int,input().split())
    for j in range(1,n+1):
        if l <= j <= r:
            pass
        else:
            an[j-1]=0

print(sum(an))

### FIXED CODE ###

n,m=map(int,input().split())
lm=0
rm=10**9

for i in range(m):
    l,r=map(int,input().split())
    lm=max(lm,l)
    rm=min(rm,r)

print(max(0,rm-lm+1))
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=1
for i in a:
	ans*=i
if ans>10**18:
	print('-1')
else:
	print(ans)

### FIXED CODE ###

n=int(input())
a=sorted(map(int,input().split()))
ans=1
for i in a:
	ans*=i
	if ans==0:
		break
	elif ans>10**18:
		print('-1')
		exit()
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))

import sys
import math

if K > 4*math.log(N):
    A = [N]*N
    print(' '.join(map(str, A)))
    sys.exit()
    

lenA = len(A)
for i in range(K):
    B = [0 for _ in range(lenA)]
#    print(B)
    for j in range(lenA):
        num = A[j]
#        print(j, num)
        B[max(0, j - num): min(lenA, j + num + 1)] = [b + 1 for b in B[max(0, j - num): min(lenA, j + num + 1)]]
#        print(j, B)
    if all([a == b for a, b in zip(A,B)]):
#        print('same')
        break
    else:
        A = B
#print(i+1)
print(' '.join(map(str, A)))

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))

lenA = len(A)
for i in range(K):
    B = [0 for _ in range(lenA)]
#    print(B)
    for j in range(lenA):
        num = A[j]
#        print(j, num)
        if j - num >= 0:
            B[max(0, j - num)] += 1
        else:
            B[0] += 1
        if j + num + 1 < lenA:
            B[min(lenA, j + num + 1)] -= 1
#        print(j, B)
    for i in range(1, lenA):
        B[i] = B[i-1] + B[i]
    if all([a == b for a, b in zip(A,B)]):
#        print('same')
        break
    else:
        A = B
#print(i+1)
print(' '.join(map(str, A)))
### BUGGY CODE ###

n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  AS.append(i+AS[-1])
  if AS[-1]>k:
    break
for i in B:
  BS.append(i+BS[-1])
  if BS[-1]>k:
    break
for i in range(len(AS)):
  for j in range(len(BS)):
    if AS[i]+BS[j]<=k:
      if i+j>r:
        r=i+j
print(r)

### FIXED CODE ###

n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  if i+AS[-1]<=k:
    AS.append(i+AS[-1])
  else:
    break
    
for i in B:
  if i+BS[-1]<=k:
    BS.append(i+BS[-1])
  else:
    break
    
j=len(BS)-1
for i in range(len(AS)):
  while AS[i]+BS[j]>k:
    j-=1
  r=max(r,i+j)
print(r)
### BUGGY CODE ###

A = list(map(int , input().split()))
B = list(map(int , input().split()))
ans = 0.0
SS = {sum(B[i:i+A[1]]):B[i:i+A[1]] for i in range(len(B)-A[1]+1)}
kitaiti = {i : (i+1)/2 for i in range(1,1001)}
for i in SS[max(SS)]:
    ans += kitaiti[i]
print(ans)

### FIXED CODE ###

A = list(map(int , input().split()))
B = list(map(int , input().split()))
kitaiti =[(i+1)/2 for i in B]
ans = []
dd = [0]
for i in range(A[0]):
    dd.append(dd[i] + kitaiti[i])
for i in range(A[1] , A[0]+1):
    ans.append(dd[i] - dd[i - A[1]])
print(max(ans))
### BUGGY CODE ###

import sys
input=sys.stdin.readline
n,k=map(int,input().split())
h=tuple(map(int,input().split()))
dp=[0]+[float("inf")]*(n-1)
for i in range(1,n):
    for j in range(max(0,i-k),i):
        dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]))
print(dp[n-1])
#print(float("inf"))

### FIXED CODE ###

import sys
input=sys.stdin.readline
n,k=map(int,input().split())
h=tuple(map(int,input().split()))
dp=[0]+[float("inf")]*(n-1)
for i in range(1,n):
    for j in range(max(0,i-k),i):
        dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]))
print(dp[n-1])
#print(float("inf"))
### BUGGY CODE ###

X,Y = map(int,input().split())

if X==Y:
    print(-1)
else:
    for i in range(10**18):
        X1 = int(X*(i+1))
        if X1 % Y != 0:
            print(str(X1))
            break
    



### FIXED CODE ###

X, Y = map(int, input().split())

if X % Y == 0:
    print(-1)
else:
   print(X)
### BUGGY CODE ###

import math

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

def combinations_count(s, r):
    return math.factorial(s) // (math.factorial(s - r) * math.factorial(r))

p = combinations_count(n, a)
q = combinations_count(n, b)

print((2**n-1-p-q)%(10**9+7))

### FIXED CODE ###

N,a,b=map(int,input().split())
m = 10**9+7

M = pow(2, N, m)

def nCr(n,r):
    if r*2>n:
        return nCr(n,n-r)
    else:
        a = b = 1
        for i in range(r):
            a = a * (n - i) % m
            b = b * (r - i) % m
        return (a * pow(b,m-2,m)) % m
 
ans = M - 1 - nCr(N,a) - nCr(N,b)
print(ans%m)
### BUGGY CODE ###

s = input()
q =int(input())
ten = 0
for _ in range(q):
    ls = tuple(map(str, input().split()))
    if len(ls)==1:
       ten +=1
    else:
        if ls[1] =='1':
            if ten%2 ==0:
                s = ls[2] +s
            else:
                s = s + ls[2]
        else:
            if ten%2 ==1:
                s = ls[2] +s
            else:
                s = s + ls[2]
if ten%2 ==1:
    s = s[::-1]
print(s)

### FIXED CODE ###

s = input()
q =int(input())
ten = 0
r = []
l = []
for _ in range(q):
    ls = tuple(map(str, input().split()))
    if len(ls)==1:
       ten +=1
    else:
        if ls[1] =='1':
            if ten%2 ==0:
                l.append(ls[2])
            else:
                r.append(ls[2])
        else:
            if ten%2 ==1:
                l.append(ls[2])
            else:
                r.append(ls[2])
s = ''.join(reversed(l))+s+''.join(r)
if ten%2 ==1:
    s = s[::-1]
print(s)
### BUGGY CODE ###

N, K = map(int, input().split())
li = list(map(int, input().split()))

i=1
k=0

while K > k:
  i = li[i-1]
  k = 1 + k

print(i)

### FIXED CODE ###

N, K = map(int, input().split())
trans = list(map(int, input().split()))

townOrder = [-1 for _ in range(N+1)]
townOrder[1] = 1
nextTown = 1
cicleStart = 0
cicleEnd = 0

for order in range(1, N+1):
  nextTown = trans[nextTown-1]
  if townOrder[nextTown] == -1:
    townOrder[nextTown] = order +1
  else:
    cicleStart = townOrder[nextTown]
    cicleEnd = order + 1
    break

exc = cicleStart -1
cicle = cicleEnd - cicleStart

if K > exc:
  K -= exc
  rest = K % cicle
  for _ in range(rest):
    nextTown = trans[nextTown-1]
  print(nextTown)
else:
  nextTown = 1
  for _ in range(K):
    nextTown = trans[nextTown-1]
  print(nextTown)
### BUGGY CODE ###

L, R = map(int, input().split())
diff = R-L
for n in range(1):
    if diff > 2019:
        ret = 0
        break
        
    results = []
    for i in range(L, R):
        for j in range(i+1,R+1):
            results.append((i*j)%2019)
        ret = min(results)
print(ret)

### FIXED CODE ###

L, R = map(int, input().split())
diff = R-L
for n in range(1):
    if diff > 2019:
        ret = 0
        break
        
        [inner for outer in init for inner in outer]
    ret = min([ (i*j)%2019 for i in range(L, R) for j in range(i+1,R+1) ])
print(ret)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
answer = 1

for i in range(N):
    answer = answer*A[i]

if answer>10**18:
    print(-1)
else:
    print(answer)


### FIXED CODE ###

import sys

N = int(input())
A = list(map(int, input().split()))
answer = 1

if 0 in A:
    print(0)
    sys.exit()

for i in range(N):
    answer = answer * A[i]
    if answer > 10**18:
        print(-1)
        sys.exit()
        
print(answer)
### BUGGY CODE ###

N = int(input())
num_list = [(i-1) + (N//i-1) for i in range(1, N+1) if N%i == 0]
print(min(num_list))

### FIXED CODE ###

N = int(input())
num_list = [(i-1) + (N//i-1) for i in range(1, int(N**0.5+1)) if N%i == 0]
print(min(num_list))
### BUGGY CODE ###

# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    a,b,k=map(int,input().split())
    l=[i for i in range(a,b+1)]

    ans=[]
    if k>b-a+1:
        ans.extend([_ for _ in range(a,b+1)])
        for i in sorted(ans):
            print(i)
    else:

        ans.extend([i for i in range(a,a+k)])
        ans.extend([i for i in range(b,b-1-(k-1),-1)])

        for i in sorted(set(ans)):
            print(i)


resolve()

### FIXED CODE ###

# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

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

    ans=[]
    if k>=b-a+1:
        for i in range(a,b+1):
            print(i)
    else:
        for i in range(a,a+k):
            ans.append(i)
        for j in range(b-k+1,b+1):
            if j not in ans:
                ans.append(j)


        for i in ans:
            print(i)


resolve()