Problem:
 Score : 300 points    Problem Statement Takahashi loves the number 7 and multiples of K .  Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots ? (Also see Output and Sample Input/Output below.)  If the sequence contains no multiples of K , print -1 instead.      Constraints  1 \leq K \leq 10^6  K is an integer.         Input Input is given from Standard Input in the following format:  K       Output Print an integer representing the position of the first occurrence of a multiple of K . (For example, if the first occurrence is the fourth element of the sequence, print 4 .)        Sample Input 1 101      Sample Output 1 4  None of 7 , 77 , and 777 is a multiple of 101 , but 7777 is.       Sample Input 2 2      Sample Output 2 -1  All elements in the sequence are odd numbers; there are no multiples of 2 .       Sample Input 3 999983      Sample Output 3 999982

Solution (Python):
k = int(input())

x = 7 % k
cnt = 1

while 10000:
    if k % 2 ==0 or k%5==0:
        print('-1')
        break
        
    if x == 0:
        print(cnt)
        break
        
    x = x*10+7
    x = x % k
    
    cnt += 1

Solution (Python):
k = int(input())
if k % 2 == 0 or k % 5 == 0:
  print(-1)
else:
  state = 7
  state %= k
  cnt = 1
  while True:
    if state == 0:
      print(cnt)
      break
    state = state * 10 + 7
    state %= k
    cnt += 1

Solution (Python):
def main():
    K = int(input())
    a = 7 % K
    for i in range(1, K+1):
        if a == 0:
            print(i)
            return
        a = a * 10 + 7
        a %= K
    print(-1)


if __name__ == '__main__':
    main()

Solution (Python):
K = int(input())
n = 0

for i in range(1, K+1):
    n = (n * 10 + 7) % K
    if n == 0:
        print(i)
        exit()
print(-1)

Solution (Python):
def main():
    K = int(input())
    a = 7
    for i in range(1, K+1):
        if a % K == 0:
            print(i)
            return
        a = a * 10 + 7
        a %= K
    print(-1)


if __name__ == '__main__':
    main()

Solution (Python):
K = int(input())
M = 7 % K

for i in range(1,K+1):
    if M == 0:
        print(i)
        exit()
    M = (M*10 + 7)%K
print(-1)

Solution (Python):
def main():
    K = int(input())
    for i in range(1, K+1):
        a = 7*(pow(10, i, 9*K)-1)
        a %= 9*K
        if a == 0:
            return print(i)
    print(-1)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    K = int(input())
    a = 7 % K
    d = 1
    for k in range(1, K+1):
        if a == 0:
            return print(k)
        d *= 10
        d %= K
        a += 7 * d
        a %= K
    print(-1)


if __name__ == '__main__':
    main()

Solution (Python):
K = int(input())
num = 7%K
ans = -1
for i in range(K):
    if num%K == 0:
        ans = i+1
        break
    num = (num*10 +7)%K
print(ans)

Solution (Python):
def main():
    K = int(input())
    num = 7%K
    ans = 0
    
    for i in range(K):
        ans += 1
        if num%K == 0:
            print(ans)
            return
        num = (num*10 +7)%K

    print(-1)
    return

main()

Solution (Python):
K = int(input())
mod = 0
for n in range(1, K+1):
  mod = (10 * mod + 7) % K
  if mod == 0:
    print(n)
    break
else:
  print(-1)

Solution (Python):
k = int(input())
mod = 7 % k
ans = 1
for i in range(k):
    if k % 2 == 0:
        ans = -1
        break
    if mod == 0:
        break
    mod = (mod*10+7)%k
    ans += 1
if mod != 0:
    ans = -1
print(ans)

Solution (Python):
from sys import stdin,stdout

n=int(stdin.readline())

dividend=7;ans=-1
for add in range(10**6+5):
    rem=dividend%n
    if rem==0:
        ans=add+1
        break
    dividend=rem*10+7
print(ans)

Solution (Python):
from sys import stdin,stdout

n=int(stdin.readline())

dividend=7;ans=-1
for add in range(10**7):
    rem=dividend%n
    if rem==0:
        ans=add+1
        break
    dividend=rem*10+7
print(ans)

Solution (Python):
k=int(input())
n=7%k
s=set()
i=1
while n not in s:
  if n == 0:
    print(i)
    exit()
  s.add(n)
  n=(10*n+7) %k
  i+=1
print(-1)

Solution (Python):
k = int(input())

if k in [2, 5, 10] == 0:
    print(-1)
    exit()

n_map = {}
current = 7 % k
cnt = 1
while True:
    if current == 0:
        print(cnt)
        exit()
    if current in n_map:
        print(-1)
        exit()
    else:
        n_map[current] = True
    cnt += 1

    current = 10 % k * current + 7
    current %= k

Solution (Python):
k = int(input())
cur = 7
t = cur%k
flag = False
for i in range(1,k+1):
    if t == 0:
        print(i)
        flag = True
        break
    else:
        t = (10*t)%k
        t += 7
        t %= k
if not flag:
    print(-1)

Solution (Python):
k = int(input())
if k%2==0 or k%5==0:
    print(-1)
    exit()
cnt=1
sup=1
if k%7==0:
    t = 9*k//7
else:
    t=9*k
while 1:
    sup*=10
    sup = sup%t
    if sup==1:
        print(cnt)
        exit()
    cnt+=1

Solution (Python):

import sys
input = sys.stdin.readline  
K = int(input())

count =1
x=7 %K

if K %2 ==0 or K %5 ==0:
    count = -1
else:

    while x %K !=0:
        count +=1
        x = (x*10 +7)%K
        
print(count)

Solution (Python):
n = int(input())
s = 7
for i in range(1, int(3e6)):
    if s%n == 0:
        print(i)
        exit()
    s = (s*10 + 7) % n
print(-1)

Solution (Python):
k = int(input())

if k == 1:
    ans = 1
elif k % 2 == 0 or k % 5 == 0:
    ans = -1
else:
    l = (9*k//7) if k % 7 == 0 else 9*k
    v = 1
    for i in range(1, l+1):
        v = (v*10) % l
        if v == 1:
            ans = i
            break
print(ans)

Solution (Python):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    k = int(input())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        sys.exit()
    if k % 7 == 0:
        l = k * 9 // 7
    else:
        l = k * 9
    r = 1       
    p = 10 ** r
    while (p % l) != 1:
        p = (p * 10) % l
        r += 1
    print(r)

if __name__ == '__main__':
    main()

Solution (Python):

k = int(input())
i = 1

if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()

if k % 7 == 0:
    L = (9 * k) // 7
else:
    L = 9 * k

for j in range(1, L + 1):
    i = (10 * i) % L
    if i == 1:
        print(j)
        exit()
print(-1)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')







def solve():
    K = II()


    used = [0] * K
    q = 7
    for i in range(K):
        q %= K
        if q == 0:
            print(i+1)
            return
        if used[q]:
            print(-1)
            return
        used[q] = 1
        q = 10*q + 7


if __name__ == '__main__':
    solve()

Solution (Python):
def calc(k):
    cur = 7 % k
    for i in range(1, k + 1):
        if cur == 0:
            return i
        else:
            cur *= 10
            cur += 7
            cur %= k
    return -1


k = int(input())
print(calc(k))

Solution (Python):
def calc(k):
    cur = 0
    for i in range(1, 10 ** 7):
        cur *= 10
        cur += 7
        cur %= k
        if cur == 0:
            return i

    return -1


k = int(input())
print(calc(k))

Solution (Python):
def main():
    k = int(input())
    if (k%2==0 or k%5==0):
        print("-1")
        return

    

    if k%7==0:
        L=9*k//7
    else:
        L=9*k
    i=1
    for n in range(1,L+1):
        i=(10*i)%L
        if i==1:
            print(n)
            return
    print("-1")
    return

main()

Solution (Python):
def calc(k):
    cur = 7 % k
    for i in range(1, 10 ** 7):
        if cur == 0:
            return i
        else:
            cur *= 10
            cur += 7
            cur %= k
    return -1


k = int(input())
print(calc(k))

Solution (Python):
K=int(input())
cnt=0
ans=0
while cnt<1000001:
  cnt+=1
  ans=(ans*10+7)%K
  if ans==0:
    print(cnt)
    break
else:
  print(-1)

Solution (Python):
k = int(input())
l = 0
s = set()
for i in range(1,9000000):
    l = (l*10+7)%k
    if l == 0:
        print(i)
        exit()
    else:
        s.add(l)
        if len(s) == i-1:
            print(-1)
            exit()
print(-1)
exit()

Solution (Python):
import os

k = int(input())
x = 7
i = 1
if k%7==0:
    l = 9*k/7
else:
    l = 9*k

if l%2==0 or l%5==0:
    print(-1)
    exit()
else:
    a = 10%l
    for i in range(1,9000001):
        if a==1:
            print(i)
            break
        a = 10*a%l

Solution (Python):
k=int(input())
if k%7==0:
    q=9*k//7
else:
    q=9*k


now=10%q
if now==1:
    print(1) ;exit()
for ans in range(2,1000000):
    now= now*10%q
    if now==1:
        print(ans)
        exit()
print(-1)

Solution (Python):
n = int(input())
ans = 1
if n % 5 == 0 or n % 2 == 0:
    print(-1)
else:
    t = 7
    while t % n != 0:
        t = t * 10 + 7
        t %= n
        ans += 1
    print(ans)

Solution (Python):
K=int(input())
if K%2==0 or K%5==0:
    print(-1)
    exit()

val = 7
ans=1
while(1):
    if val%K==0:
        print(ans)
        exit()
    val = (val*10+7) % K
    ans +=1

Solution (Python):
k = int(input())

lsd = k % 10
if lsd % 2 == 0 or lsd == 5:
    print(-1)
    exit()

dct = {0: 0}
for i in range(1, 10):
    dct[(lsd*i) % 10] = i

l = k
c = 0
while l > 0:
    t = l % 10
    n = dct[(7 - t) % 10]
    l += (k*n)

    l //= 10
    c += 1

print(c)

Solution (Python):
k=int(input())
c=7
a=-1
for i in range(1,10**6):
    c%=k
    if c%k==0:
        a=i
        break
    else:
        c*=10
        c+=7
print(a)

Solution (Python):

k = int(input())

if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    n = 7
    cnt = 1
    for i in range(k):
        if n % k == 0:
            break
        cnt += 1
        n = (n * 10 + 7) % k
    print(cnt)

Solution (Python):
k = int(input())

x = 7%k

for i in range(1,k+1):
    if x == 0:
        print(i)
        exit()
    x = (10*x+7)%k
    
print(-1)

Solution (Python):
K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()

i = 0
ai = 0
while True:
    ai = (ai * 10 + 7) % K
    i += 1
    if ai == 0:
        break
print(i)

Solution (Python):
def main():

    k = int(input())

    result = -1
    m = 7
    for i in range(1,k+1):
        check = m % k
        if check == 0:
            result = i
            break
        m = (10*m + 7) % k
    
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):
K = int(input())
m = 0
for k in range(1,K + 1):
  m = m * 10 + 7
  m = m % K
  if m == 0:
    print(k)
    break
if m > 0:
  print(-1)

Solution (Python):
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()
now = 7
ans = 1
while True:
    now %= k
    if now == 0:
        print(ans)
        exit()
    ans += 1
    now = now*10 + 7

Solution (Python):
import math
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    a = 0
    result = -1
    for i in range(k):
        a = (a*10 + 7)%k
        if a == 0:
            result = i+1
            break

    print(result)

Solution (Python):
k = int(input())

if str(k)[-1] not in ["1","3","7","9"]:
    print(-1)
    exit()

tmp = 7%k
i = 1
while True:
    if tmp == 0:
        print(i)
        exit()
    tmp = (tmp*10 + 7)%k
    i += 1

Solution (Python):
K = int(input())
m = 7 % K
for i in range(1, K + 1):
    if m % K == 0:
        print(i)
        break
    m = (10 * m + 7) % K
else:
    print(-1)

Solution (Python):
K = int(input())

t = 7 % K
if t == 0:
    print(1)
    exit()

for i in range(2, 10**6):
    t = (t * 10 + 7) % K
    if t == 0:
        print(i)
        exit()

print(-1)

Solution (Python):
K=int(input())
i=1
x=7
mod=set()
while True:
  if x%K==0:
    print(i)
    break
  else:
    if x%K in mod:
      print(-1)
      break
    mod.add(x%K)
    x=(x%K)*10+7
    i+=1

Solution (Python):
k = int(input())
ans = 1
seen = set()
mod = 7%k
while mod != 0 and mod not in seen:
    seen.add(mod)
    mod = (10*mod + 7)%k
    ans += 1

if mod == 0:
    print(ans)
else:
    print(-1)

Solution (Python):
K = int(input())

flag = [0 for _ in range(K)]  

if 7%K == 0:
    print(1)
else:
    now_n = 7%K
    flag[now_n] = 1
    while True:
        next_n = (now_n*10 + 7) % K
        if next_n == 0:
            print(sum(flag)+1)
            exit()
        elif flag[next_n] == 0:
            now_n = next_n
            flag[now_n] = 1
        else:
            print(-1)
            exit()

Solution (Python):
from math import log10
x = int(input())

if x % 7 == 0:
    L = (x*9)/7
else:
    L = 9*x

if L % 2 == 0 or L % 5 == 0:
    print(-1)
    exit(0)

n = 1
amari = 1
while n < 9000000:
    amari = (amari*10) % L
    if amari == 1:
        print(n)
        exit(0)
    else:
        n += 1
print(-1)

Solution (Python):
K = int(input())

t = 7 % K
if t == 0:
    print(1)
    exit()
for i in range(2, 10**6):
    t = (t * 10 + 7) % K
    if t == 0:
        print(i)
        exit()
print(-1)

Solution (Python):
k=int(input())
n=7%k
for i in range(1,k+1):
  if n==0:
    print(i)
    exit()
  n=(10*n+7)%k
print(-1)

Solution (Python):
k = int(input())
c = 0
if k%2 ==0 or k%5==0:
    print(-1)
    c=1
elif k==1:
    print(1)
    c=1
if c==0:
    t = 7

    for i in range(k):
        if int(t)%k==0 :
            print(i+1)
            break
        t = (10*t+7)%k

Solution (Python):
K = int(input())
n = 7 % K
for k in range(1, K + 1):
    if n == 0:
        print(k)
        exit()
    n = (n*10+7)%K
print(-1)

Solution (Python):
def main():
    K = int(input())
    l = [False] * K
    ans = 1
    now = 0
    while True:
        now = now * 10 + 7
        now %= K
        if now == 0:
            print(ans)
            break

        if l[now]:
            print(-1)
            break
        
        l[now] = True
        ans += 1

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    K = int(input())
    l = [False] * K
    ans = 1
    now = 0
    while True:
        now = now * 10 + 7
        now %= K
        if now == 0:
            print(ans)
            break

        if l[now]:
            print(-1)
            break
        
        l[now] = True
        ans += 1

if __name__ == '__main__':
    main()

Solution (Python):
k=int(input())
n=7%k
for i in range(1,k+1):
  if n == 0:
    print(i)
    exit()
  n=(n*10+7) % k
print(-1)

Solution (Python):
K = int(input())

r = 0
for i in range(1, K+1):
    r = (r*10 + 7) % K
    if r == 0: break
else:
    i = -1

print(i)

Solution (Python):
k=int(input())
n=7%k
for i in range(1,k+1):
  if n == 0:
    print(i)
    exit()
  n=(n*10+7) % k
print(-1)

Solution (Python):
k = int(input())
x = 0
for i in range(1, k + 1):
    x = x * 10 + 7
    if x % k == 0:
        print(i)
        exit()
    x %= k
print(-1)

Solution (Python):

def main():
    k = int(input())
    cnt = 7
    
    for i in range(1, k+1):
        if cnt%k == 0:
            print(i)
            exit()
        cnt = (10*cnt+7) % k
    else:
        print(-1)

if __name__ ==  "__main__":
    main()

Solution (Python):
K = int(input())

cur = 7
for i in range(1, K + 1):
    if cur % K == 0:
        print(i)
        quit()
    cur = (10 * cur + 7) % K

print(-1)

Solution (Python):
K = int(input())
x = 7
ans = 1
if x%K==0:
  print(ans)
  exit()
visited = [0]*(K+1)
while x!=0:
  x %= K
  x = x*10+7
  x %= K
  if visited[x]:
    print(-1)
    exit()
  visited[x] = 1
  ans += 1
print(ans)

Solution (Python):
K = int(input())

a = 0
ans = -1
S = set()
for i in range(1, K + 1):
    a = a * 10 + 7
    a %= K
    if a == 0:
        ans = i
        break
    elif a in S:
        break
    S.add(a)
print(ans)

Solution (Python):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    k = int(input())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        sys.exit()
    p = 7       
    plus = 7    
    r = 1       
    while (p % k) != 0: 
        plus = (plus * 10) % k   
        p += plus                
        p = p % k                
        r += 1
    print(r)

if __name__ == '__main__':
    main()

Solution (Python):
K = int(input())

seen = set()

extra = 7 % K
i = 1

while extra not in seen:

    if extra == 0:
        print(i)
        exit()
    
    seen.add(extra)
    extra = (extra * 10 + 7) % K
    i += 1

print(-1)

Solution (Python):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    k = int(input())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        sys.exit()
    p = 7
    plus = 7
    amari = set()
    r = 1
    while (p % k) != 0:
        if p in amari:
            print(r, -1, p)
            sys.exit()
        else:
            amari.add(p)
            plus = (plus * 10) % k
            p += plus
            p = p % k
            r += 1
    print(r)

if __name__ == '__main__':
    main()

Solution (Python):
k = int(input())

mod = 7 % k
for i in range(1, 10**6):
    if mod == 0:
        print(i)
        exit()
    mod = (mod * 10 + 7) % k

print(-1)

Solution (Python):
K = int(input())
rem_set = set()
rem = 7%K
i = 1
while True:
    if rem == 0:
        print(i)
        break
    if rem in rem_set:
        print(-1)
        break
    i += 1
    rem_set.add(rem)
    rem = (rem*10 + 7)%K

Solution (Python):
n=int(input())
e=len(str(n))
e1=int('7'*e)
if e1<n:
    e1=e1*10+7
tr=1
s=set()
t=e1%n
ans=len(str(e1))
while(t!=0):
    if t in s:
        tr=0
        break
    s.add(t)
    e1=t*10+7
    t=e1%n
    ans+=1
if tr==0:
    print(-1)
else:
    print(ans)

Solution (Python):
k=int(input())

mod=[0]*k
c=7
cnt=1

while True:
    if c%k==0:
        print(cnt)
        break
    
    mod[c%k]=1

    c*=10
    c+=7
    c%=k
    cnt+=1

    if mod[c]==1:
        print(-1)
        break

Solution (Python):
K = int(input())
m = 7%K
ans = 1
s = set()
s.add(m)
for _ in range(K):
    
    if m == 0:
        print(ans)
        break
    m = (m*10+7)%K
    if m in s:
        print('-1')
        break
    else:
        s.add(m)
    ans += 1

Solution (Python):
K = int(input())
before = 0
for i in range(1, 10**6+1):
    n = before*10+7
    if n >= K and n%K == 0:
        print(i)
        exit()
    before = n%K
print(-1)

Solution (Python):
k=int(input())

ans=7
cnt=1
if k%2==0 or k%5==0:
    print(-1)
else:
    while True:
        if ans%k==0:
            break
        ans=(ans*10+7)%k
        cnt+=1
    print(cnt)

Solution (Python):
K=int(input())
List = list(str(K))
i = len(List)
tryNum = 7*10**i
res = -1
if K % 2 == 0 or K % 5 == 0:
  print(res)
else:
  flag = True
  mid=0
  K=9*K
  N=0
  while flag:
    N = tryNum % K
    if  N == 7 :
      res = i
      flag = False
    else:
      i += 1
      tryNum= N*10
  print(res)

Solution (Python):
def main(k):
    size, res = 1, 7 % k
    while res and size <= k:
        res = (res * 10 + 7) % k
        size += 1
    return -1 if size > k else size


if __name__ == '__main__':
    k = int(input())
    print(main(k))

Solution (Python):
K = int(input())

c = 0

a = 7 % K
for i in range(K + 1):
    if a == 0:
        print(i + 1)
        exit()
    a = (a * 10 + 7) % K

print(-1)

Solution (Python):
k = int(input())
mod = 7


for i in range(10**6):
    j = mod % k

    if i > 1 and j == 7:
        print(-1)
        exit()
    if j == 0:
        print(i + 1)
        exit()
    else:
        
        
        
        
        mod = j * 10 + 7
print(-1)

Solution (Python):
def main(k):
    size, res = 1, 7 % k
    while res and size <= 1_000_000:
        res = (res * 10 + 7) % k
        size += 1
    return -1 if size > 1_000_000 else size


if __name__ == '__main__':
    k = int(input())
    print(main(k))

Solution (Python):
k = int(input())
checked = [False] * k

surplus = 0
ans = 1
while 1:
    surplus = ((surplus * 10) + 7) % k
    if checked[surplus]:
        print(-1)
        exit()
    if surplus == 0:
        break
    checked[surplus] = True
    ans += 1

print(ans)

Solution (Python):
k = int(input())
t = 7
ans=0
for i in range(k):
    if t%k==0:
        ans=i+1
        break
    else:
        t = (t*10+7)%k
        
if ans >0:
    print(ans) 
else:
    print(-1)

Solution (Python):
k = int(input())
t = 7
ans=0

for i in range(k):
    if t%k==0:
        ans =i+1
        break
    else:
        t = (t*10+7)%k
        
print(ans if ans >0 else -1)

Solution (Python):
K = int(input())
cnt = 1
mod = 7 % K
for i in range(K):
    if mod == 0: 
        print(cnt)
        exit()
    mod = (mod * 10 + 7) % K    
    cnt += 1
print(-1)

Solution (Python):


k = int(input())

x = 7%k
for i in range(1, k+1):
    if x == 0:
        print(i)
        exit(0)
    x=(10*x+7)%k

print(-1)

Solution (Python):



def main():
    import sys
    input = sys.stdin.readline

    k = int(input())
    x = 7 % k  

    
    
    
    
    for i in range(1, k + 1):
        if x == 0:
            print(i)
            exit()

        x = (x * 10 + 7) % k

    print(-1)


if __name__ == '__main__':
    main()

Solution (Python):


K=int(input())
ans=-1
if K==1:
    ans=1
elif K==2 or K==5 or K==10:
    ans=-1
else:
    p=0
    for i in range(1,K+1):
        p = (p*10+7)%K 
        
        if p==0:
            ans=i
            break

print(ans)

Solution (Python):
K = int(input())

c = 0

a = 7 % K
for i in range(K + 1):
    if a == 0:
        print(i + 1)
        exit()
    a = (a * 10 + 7) % K

print(-1)

Solution (Python):
K=int(input())
N=7%K
cnt=0
ret=-1
while cnt< K:
  cnt+=1
  if (N % K) == 0:
    print (cnt)
    break
  N=(N*10+7)%K
else:
  print (-1)

Solution (Python):
from collections import defaultdict
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    K = int(input())

    if not K % 2:
        print(-1)
        return

    x = defaultdict(int)
    mod = 7 % K
    for i in range(K):
        if not mod:
            print(i + 1)
            break
        if x[mod]:
            print(-1)
            break
        x[mod] = 1
        mod = (mod * 10 + 7) % K


main()

Solution (Python):
k = int(input())
if k % 7 == 0:
    L = 9 * k // 7
else:
    L = 9 * k
out = -1
s = 10
for i in range(L):
    if s % L == 1:
        out = i + 1
        break
    else:
        s = (s % L) * 10
print(out)

Solution (Python):
k = int(input())

now = 7

for i in range(k+1):
    now %= k
    if now == 0:
        print(i+1)
        exit()
    else:
        now = now * 10 +7
        
print(-1)

Solution (Python):
K = int(input())
x = 7 % K

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

else: print(-1)

Solution (Python):
K = int(input())
x = 7 % K
num_list = []

for count in range(1, K + 1):
  if x == 0:
    print(count)
    break
  x = (x * 10 + 7) % K

else: print(-1)

Solution (Python):
import math
import time
start=time.time()
K=int(input())
ans=0
if K%2==0:
    print(-1)
else:
    if K%7==0:
        K//=7
    k=1
    kk=1
    while True:
        now=time.time()
        if (now-start)>1.8:
            ans=-1
            break
        kk*=10
        kk%=9*K
        if kk==1:
            ans=k
            break
        else:
            k+=1


    print(ans)

Solution (Python):
k = int(input())

def answer(k):
    if k % 2 == 0 or k % 5 == 0:
        return -1
    d = 1
    r = 7
    while r % k != 0:
        r = 10 * r + 7
        r %= k
        d += 1
    return d

print(answer(k))

Solution (Python):








from math import *

k = int(input())

if(k % 2 == 0 or k % 5 == 0):
    print(-1)
else:
    ans = 1
    num = 7 % k
    while(num > 0):
        num = ((num * 10) + 7) % k
        ans = ans + 1
    print(ans)

Solution (Python):
k=int(input())


mod=k
flag=True
for i in range(1,10**6+1):
    if i<=7:
        if mod > 7 * int(str(1) * i):
            continue
        else:
            pass
    if mod == k:
        mod = 7 * int(str(1) * i) % mod
        if mod == 0:
            print(i)
            exit()
    else:
        mod = (mod * 10 + 7) % k
        if mod == 0:
            print(i)
            exit()

print(-1)

Solution (Python):

def resolve():
    K = int(input())
    val = 7
    for i in range(K):
        if val % K == 0:
            print(i+1)
            break
        val = (val*10 + 7) % K
    else:
        print(-1)

if '__main__' == __name__:
    resolve()

Solution (Python):
k=int(input())


mod=7
if mod%k==0:
     print(1)
     exit()

for i in range(2,10**6+1):
      mod= (mod*10+7)%k
      if mod==0:
          print(i)
          exit()

print(-1)

Solution (Python):
n=int(input());p=7%n;c=-1
for i in range(10**6):
	if p==0:c=i+1;break
	p=(p*10+7)%n
print(c)

Solution (Python):
k=int(input())

cur=0
for i in range(k+2):
    cur=(cur*10+7)%k
    if cur==0:
        print(i+1)
        exit()

print(-1)

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())


def solve():
    divs = set()
    r = 0
    cnt = 1
    while (r * 10 + 7) % N not in divs:
        r = (r * 10 + 7) % N
        divs.add(r)
        if r == 0:
            return cnt
        cnt += 1

    return -1


print(solve())

Solution (Python):
cnt = 1
mod = 7
k = int(input())
for i in range (k):
    if mod % k == 0:
        break
    cnt +=1
    mod = (mod * 10 + 7) % k
if mod % k == 0:
    print(cnt)
else:
    print(-1)

Solution (Python):
k = int(input())
if k%2==0 or k%5==0:
  print(-1)
else:
  a = 7
  cnt = 1
  while True:
    if a%k==0:
      break
    a = (a*10+7)%k
    cnt += 1
  print(cnt)

Solution (Python):
K = int(input())

t = 7
for i in range(K):
    if t % K == 0:
        print(i + 1)
        break
    t = (t * 10 + 7) % K
else:
    print(-1)

Solution (Python):
def main(N):
    if L % 2 == 0 or L % 5 == 0:
        print(-1)
        return
    else:
        before = 10 % L
        if before == 1:
            print(1)
            return
        for i in range(L):
            before = (10 * before) % L
            if before == 1:
                print(i + 2)
                return
        print("error")
        return

K = int(input())
if K % 7 == 0:
    L = 9 * K // 7
else:
    L = 9 * K

main(L)

Solution (Python):
K = int(input())

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

Solution (Python):
K=int(input())
def x():
    count=0
    for i in range(K):
        count =(10*count+7)%K
        if count==0:
            return i+1
    return -1    
print(x())

Solution (Python):
k = int(input())
s = 1
t = 1
for i in range(1, k + 1):
    if 7 * s % k == 0:
        print(i)
        break
    t = 10 * t % k
    s = (s + t) % k
else:
    print(-1)

Solution (Python):
k = int(input())
x = 7
p = 0
for i in range(1, k + 3):
  p = (p + x) % k
  if p == 0:
    print(i)
    exit()
  x = (10 * x) % k
print(-1)

Solution (Python):
K = int(input())
F = set()
val = 7
flg = True
for i in range(K+6):
  if val % K == 0:
    flg = False
    print(i+1)
    break
  F.add(val%K)
  val *= 10
  val += 7
  val %= K
  if val % K in F:
    break
if flg:
  print(-1)

Solution (Python):
N=int(input())
a=0
ans=1
num=0
if N%2==0 or N%5==0:
   print(-1)
   exit()
while True:
   num=(num*10+7)%N
   if num==0:
      print(ans)
      exit()
   ans+=1

Solution (Python):
K = int(input())
if K % 2 == 0 or K % 5 == 0:
  print(-1)
elif K % 7 == 0:
  L = 9 * K / 7
  i = 1
  x = 1
  while True:
    y = x * 10
    if y % L == 1:
      print(i)
      exit()
    else:
      x = y % L
      i += 1
else:
  L = 9*K
  i = 1
  x = 1
  while True:
    y = x * 10
    if y % L == 1:
      print(i)
      exit()
    else:
      x = y % L
      i += 1

Solution (Python):
K = int(input())
num = 7
ans = -1
for i in range(K):
    if num % K == 0:
        ans = i + 1
        break
    num = (num * 10 + 7) % K
print(ans)

Solution (Python):
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

k = r()
val = 7%k
ans = False
for i in range(1,10**6+1):
    if val==0:
        ans = True
        print(i)
        break
    val = (val*10+7)%k
if not ans:
    print(-1)

Solution (Python):
n = int(input())
x, found = 0, False
for i in range(1, n + 1):
  x = ((10 * x) + 7)%n
  if x == 0:
    print(i)
    found = True
    break

if not found:
  print(-1)

Solution (Python):
K = int(input())

t = 7
for i in range(K):
    if t % K == 0:
        print(i + 1)
        break
    t = (t * 10 + 7) % K
else:
    print(-1)

Solution (Python):
k = int(input())
a = 0
 
for i in range(k + 10):
    a = (a*10 + 7)%k
    if a == 0:
        print(i + 1)
        exit()
print(-1)

Solution (Python):
K = input()
K = int(K)

def seven():
    seven_i = 0
    count = 0
    for i in range(K):
        seven_i = ((10*seven_i) + 7) % K
        count += 1
        if seven_i % K == 0:
            return count
    return -1

print(seven())

Solution (Python):


K = int(input())

tmp = 0
stat = True
for i in range(1, K+10):
    tmp *= 10
    tmp %= K
    tmp += 7
    tmp %= K
    
    if(tmp == 0):
        print(i)
        stat = False
        break

if(stat):
    print(-1)



'''
seven = []
tmp = 0
for i in range(10**4+10):
    tmp *= 10
    tmp += 7
    seven.append(tmp)










for K in range(1, 200):
    for j in range(10**4 + 10):
        
        
        if(seven[j] % K == 0):
        
            print('K:{}, j+1:{}, seven[j]/K:{}'.format(K, j+1, seven[j]/K))
            
            
            break
        
            




'''

Solution (Python):
k = int(input())
a = 0

for i in range(k + 10):
    a = (a*10 + 7)%k
    if a == 0:
        print(i + 1)
        exit()
print(-1)

Solution (Python):
K = int(input())

if K % 7 == 0:
    L = 9 * K / 7
else:
    L = 9 * K

if L % 2 == 0 or L % 5 == 0:
    print(-1)
else:
    rest = 1
    ans = 0
    while True:
        rest *= 10
        ans += 1
        rest = rest % L
        if rest == 1:
            break
    print(ans)

Solution (Python):
k = int(input())
x = 7%k
i = 1
for i in range(1,k+1):
    if x==0:
        break    
    x = (x*10+7)%k
    i += 1
    
if x == 0:
    print(i)
else:
    print('-1')

Solution (Python):
k = int(input())
val = 7
visited = set()
counter = 1
while len(visited) < k:
    val %= k
    if val in visited:
        print(-1)
        break
    elif val % k == 0:
        print(counter)
        break
    else:
        visited.add(val)
        val = (val * 10 + 7) % k
        counter += 1

Solution (Python):
k = int(input())
seen = set()
num = 7
while True:
  if num%k==0:
    print(len(seen)+1)
    exit()
  elif num%k in seen:
    print("-1")
    exit()
  else:
    seen.add(num%k)
    num = (num*10+7)%k

Solution (Python):
def main():
    k = int(input())
    m = 7%k
    for i in range(1, k+1):
        if m == 0:
            print(i)
            exit()
        m = (m*10 + 7)%k
    print(-1)

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    K = int(input())
    if K%2 == 0:
        return -1
    ans = 1
    amari_reserve = 7%K
    amari = amari_reserve
    if amari_reserve == 0:
        return ans

    while (ans <= K):
        ans += 1
        amari = (10*amari+7) % K
        if amari == 0:
            return ans
        if amari == amari_reserve:
            return -1

    return -1


print(main())

Solution (Python):
k = int(input())
j = 7

for i in range(k):
	if j % k < 1:
		print(i + 1)
		exit()
	j = (j * 10 + 7) % k
print(-1)