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-----
101

-----Sample Output-----
4

None of 7, 77, and 777 is a multiple of 101, but 7777 is.

Difficulty: EASY

Solutions:
K = int(input())

def calc(K):
	if K % 2 == 0:
		return -1
	seven = 0
	for i in range(1, K + 1):
		seven *= 10
		seven += 7
		seven %= K
		if seven == 0:
			return i
	return -1
print(calc(K))


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


(k, R, a) = (int(input()), 7, -1)
for i in range(1, k + 1):
	if not R % k:
		a = i
		break
	R = (R * 10 + 7) % k
print(a)


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


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')


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


K = int(input())
s = 0
i = 1
while i <= K:
	s = (s * 10 + 7) % K
	if s == 0:
		print(i)
		break
	i += 1
if i > K:
	print(-1)


m = int(input())
p = 0
for j in range(1, m + 1):
	p = (p * 10 + 7) % m
	if p == 0:
		print(j)
		exit()
print('-1')


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


k = int(input())
if k % 2 == 0:
	print(-1)
	return
if k % 5 == 0:
	print(-1)
	return
if k % 7 == 0:
	k = k // 7
r = 1
m = 10
while True:
	m %= 9 * k
	if m == 1:
		print(r)
		return
	r += 1
	m *= 10


k = int(input())
if k % 2 * (k % 5) == 0:
	print(-1)
else:
	i = 1
	x = 7
	while x % k:
		x = (x * 10 + 7) % k
		i += 1
	print(i)


k = int(input())
s = 7
i = 1
while s % k != 0:
	i += 1
	s = 10 * (s % k) + 7
	if i == k + 1:
		break
else:
	print(i)
	exit()
print(-1)


k = int(input())
if k % 2 == 0 or k % 5 == 0:
	print(-1)
else:
	exc = 0
	for i in range(1, 10 ** 8):
		exc = exc * 10 + 7
		exc = exc % k
		if exc % k == 0:
			ans = i
			break
	print(ans)


K = int(input())
wa = 0
kake = 1
for i in range(1, K + 1):
	if i != 1:
		kake = kake * 10 % K
	wa += 7 * kake
	if wa % K == 0:
		print(i)
		return
print(-1)


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


from math import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import heapq
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
INF = float('inf')
from sys import stdin
readline = stdin.readline

def readInts():
	return list(map(int, readline().split()))

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())
k = I()
i = 0
a = 0
while i < k:
	a = (a * 10 + 7) % k
	if a == 0:
		print(i + 1)
		return
	i += 1
print(-1)


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


K = int(input())
frag = [0] * (K + 1)
frag[1] = 7 % K
for i in range(2, K + 1):
	frag[i] = (frag[i - 1] * 10 + 7) % K
for i in range(1, K + 1):
	if frag[i] == 0:
		print(i)
		break
else:
	print(-1)


t = int(input())
f = 0
n = t
for i in range(10 ** 6 + 1):
	if n == 0:
		f = 1
		print(i)
		break
	n = (n * 10 + 7) % t
if f == 0:
	print(-1)


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


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


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


k = int(input())
if k % 2 * (k % 5) < 1:
	exit(print(-1))
(a, t, m) = (1, 7, 7)
while m % k:
	a += 1
	t = t * 10 % k
	m += t
print(a)


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


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)


k = int(input())
k *= 9
amari = 63
for i in range(1, 10 ** 6 + 1):
	amari %= k
	if amari == 0:
		print(i)
		break
	else:
		amari = amari * 10 + 63
else:
	print(-1)


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

def __starting_point():
	main()
__starting_point()


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


k = int(input())
a = 7
if k == 1 or k == 7:
	print(1)
	return
for i in range(k):
	a *= 10
	a += 7
	a %= k
	if a == 0:
		print(i + 2)
		return
print(-1)


k = int(input())
ml = []
a = 7
m = 7
i = 0
while m > 0:
	m = a % k
	a = 10 * m + 7
	i += 1
	if i > k:
		i = -1
		break
print(i)


k = int(input())
if k % 2 == 0 or k % 5 == 0:
	print(-1)
	exit()
num = 7
num %= k
ans = 1
while num != 0:
	num = 10 * num + 7
	num %= k
	ans += 1
print(ans)


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)


K = int(input())
a = [7] * (K + 1)
a[0] %= K
for i in range(1, K + 1):
	a[i] = (10 * a[i - 1] + 7) % K
ans = [i + 1 for (i, ai) in enumerate(a) if ai == 0]
if len(ans) > 0:
	print(ans[0])
else:
	print(-1)


k = int(input())
kkk = [0] * k
kkk[0] = 7 % k
ans = -1
for i in range(1, k):
	kkk[i] = (kkk[i - 1] * 10 + 7) % k
for j in range(k):
	if kkk[j] == 0:
		ans = j + 1
		break
print(ans)


def f(k):
	r = 7 % k
	for i in range(k):
		if r == 0:
			return i + 1
		r = (r * 10 + 7) % k
	return -1
print(f(int(input())))


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


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)


K = int(input())
if K % 2 == 0 or K % 5 == 0:
	print(-1)
else:
	a = 7
	i = 0
	while True:
		if a % K == 0:
			print(i + 1)
			break
		else:
			(a, i) = ((a * 10 + 7) % K, i + 1)


import sys
K = int(input())
a = 7 % K
for k in range(K + 2):
	if a == 0:
		print(k + 1)
		break
	a = (a * 10 + 7) % K
else:
	print(-1)


K = int(input())
i = 7 % K
se = set([i])
cnt = 1
while True:
	if i == 0:
		print(cnt)
		break
	cnt += 1
	i = (i * 10 + 7) % K
	if i in se:
		print(-1)
		break
	else:
		se.add(i)


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


def main():
	K = int(input())
	if K % 2 == 0 or K % 5 == 0:
		print(-1)
		return
	r = 7 % K
	n = 1
	while r != 0:
		r = (10 * r + 7) % K
		n += 1
	print(n)
	return

def __starting_point():
	main()
__starting_point()


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)


K = int(input())
f = 1
j = 7 % K
while f < K and j != 0:
	j = (j * 10 + 7) % K
	f += 1
if j == 0:
	print(f)
else:
	print('-1')


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


def c174(k):
	ans = -1
	sebun = 7
	for i in range(k):
		if sebun % k == 0:
			ans = i + 1
			return ans
		sebun = sebun % k * 10 + 7
	return ans

def main():
	k = int(input())
	print(c174(k))

def __starting_point():
	main()
__starting_point()


k = int(input())
n = 7
n = n % k
j = 0
i = 1
if k % 2 == 0 or k % 5 == 0:
	print(-1)
	return
if n == 0:
	print(i)
	return
while n != 0:
	j = n
	n = (n * 10 + 7) % k
	if j == n:
		print(-1)
		return
	i += 1
print(i)


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)


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


K = int(input())
MOD = 7 % K
if MOD == 0:
	print(1)
	return
for i in range(2, K + 1):
	MOD = (MOD * 10 + 7) % K
	if MOD == 0:
		print(i)
		return
print(-1)


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)


def main():
	K = int(input())
	rn = [0]
	r = [0] * K
	for i in range(K):
		ri = (rn[-1] * 10 + 7) % K
		if ri == 0:
			print(i + 1)
			return 0
		elif r[ri] == 0:
			r[ri] = 1
			rn.append(ri)
		elif r[ri] == 1:
			print(-1)
			return 0
main()


import sys

def input():
	return sys.stdin.readline().strip()

def I():
	return int(input())

def LI():
	return list(map(int, input().split()))

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def S():
	return input()

def LS():
	return input().split()
INF = float('inf')
k = I()
ans = -1
a = [0] * (k + 1)
a[1] = 7 % k
for i in range(2, k + 1):
	a[i] = (a[i - 1] * 10 + 7) % k
for i in range(1, k + 1):
	if a[i] == 0:
		print(i)
		return
print(-1)


a = int(input())
b = 7
for i in range(a):
	if b % a == 0:
		print(i + 1)
		break
	b = 10 * b % a + 7
	if i == a - 1:
		print(-1)
		break


import sys
from collections import deque, Counter, defaultdict
import bisect
import heapq
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
inf = 10 ** 18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
k = ri()
reses = []
cnt = 1
tmp = 7
for i in range(k + 1):
	res = tmp % k
	if res == 0:
		print(cnt)
		return
	tmp = res * 10 + 7
	cnt += 1
print(-1)


I = lambda : list(map(int, input().split()))
(k,) = I()
ans = -1
s = 7 % k
c = 0
while c <= 10 ** 6:
	c += 1
	if s == 0:
		ans = c
		break
	s = (s * 10 + 7) % k
print(ans)


def main(K):
	ans = -1
	if K % 2 == 0 or K % 5 == 0:
		return ans
	else:
		seven = 7
		for i in range(K):
			if seven % K == 0:
				ans = i + 1
				return ans
			seven = (seven * 10 + 7) % K

def __starting_point():
	K = int(input())
	ans = main(K)
	print(ans)
__starting_point()


k = int(input())
if 7 % k == 0:
	print(1)
	return
a = [7 % k]
for i in range(2, k + 1):
	aa = 10 % k * a[-1] + a[0]
	a.append(aa % k)
	if a[-1] % k == 0:
		print(i)
		return
print(-1)


k = int(input())
start = 7 % k
ans = start
con = 1
if k % 2 == 0 or k % 5 == 0:
	print('-1')
	return
while True:
	if ans == 0:
		print(con)
		break
	else:
		con += 1
		ans = ans * 10 + 7
		ans = ans % k
		if ans == start:
			print('-1')
			break


K = int(input())
a = [7 % K]
for i in range(1, K):
	a.append((10 * a[i - 1] + 7) % K)
flag = False
for i in range(len(a)):
	if a[i] == 0:
		print(i + 1)
		flag = True
		break
if not flag:
	print(-1)


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


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


k = int(input())
if k % 2 == 0 or k % 5 == 0:
	print(-1)
else:
	i = 1
	t = 7
	while t % k != 0:
		i += 1
		t = (t * 10 + 7) % k
	print(i)


k = int(input())
s = 0
for n in range(0, 10 ** 6):
	s += 7 * pow(10, n, k)
	if s % k == 0:
		print(n + 1)
		exit()
print('-1')


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


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))


K = int(input())
a = 7 % K
cnt = 1
while a:
	a = (10 * a + 7) % K
	cnt += 1
	if K < cnt:
		cnt = -1
		break
print(cnt)


mod = int(input())
a = {}
b = int(0)
flag = int(0)
ans = int(0)
for i in range(mod):
	b = b * 10 + 7
	b = b % mod
	if b == 0:
		flag = 1
		ans = int(i) + 1
		break
	else:
		pass
if flag == 1:
	print(ans)
else:
	print('-1')


k = int(input())
if k % 2 < 1 or k % 5 < 1:
	print(-1)
	exit()
a = 1
t = 7
m = 0
while 1:
	t = t * 10 % k
	m += t
	if m % k:
		a += 1
	else:
		break
print(a)


k = int(input())
x = i = 0
while i < 7000000.0:
	i += 1
	x = (x * 10 + 7) % k
	x < 1 > exit(print(i))
print(-1)


K = int(input())
if K % 2 == 0 or K % 5 == 0:
	print(-1)
	return
r = 7 % K
ans = 1
while r != 0:
	r = (r * 10 + 7) % K
	ans += 1
print(ans)


def ans(k):
	arry = [None] * k
	arry[0] = 7 % k
	for i in range(k - 1):
		arry[i + 1] = (10 * arry[i] + 7) % k
	for i in range(k):
		if arry[i] == 0:
			return i + 1
	return -1
K = int(input())
print(ans(K))


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


k = int(input())
(a, bk) = (7, 7)
for i in range(1, k + 1):
	if i != 1:
		bk = bk * 10 % k
		a += bk
	a %= k
	if a == 0:
		print(i)
		return
print(-1)


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


k = int(input())
r = 7 % k
for i in range(2 * k):
	if r == 0:
		print(i + 1)
		return
	r = (r * 10 + 7) % k
print(-1)


k = int(input())
(x, ans) = (7 % k, 1)
for _ in range(0, int(10000000.0)):
	if x == 0:
		break
	x = (x * 10 + 7) % k
	ans += 1
print(ans if x == 0 else -1)


n = int(input())
f = 0
for i in range(n):
	f = f * 10 + 7
	f %= n
	if f == 0:
		print(i + 1)
		break
else:
	print(-1)


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


k = int(input())

def cal(k):
	n = 7
	for i in range(1, 10000000):
		if n % k == 0:
			return i
		else:
			n = (n * 10 + 7) % k
	return -1
print(cal(k))


K = int(input())
R = 0
for i in range(1, K + 10):
	R *= 10
	R += 7
	R %= K
	if R == 0:
		print(i)
		import sys
		return
print(-1)


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


k = int(input())
if k % 7 == 0:
	l = 9 * (k // 7)
elif k % 5 == 0 or k % 2 == 0:
	print(-1)
	return
else:
	l = 9 * k
n = 10
for i in range(1, l):
	if n % l == 1:
		print(i)
		return
	n = 10 * (n % l)
print(-1)


import sys, os.path
sys.setrecursionlimit(10 ** 5)

def mod():
	return 10 ** 9 + 7

def i():
	return sys.stdin.readline().strip()

def ii():
	return int(sys.stdin.readline())

def li():
	return list(sys.stdin.readline().strip())

def mii():
	return map(int, sys.stdin.readline().split())

def lii():
	return list(map(int, sys.stdin.readline().strip().split()))

def solve():
	a = ii()
	val = 7 % a
	for i in range(1, 10 ** 7):
		if val == 0:
			print(i)
			return
		val = (val * 10 + 7) % a
	print(-1)
for _ in range(1):
	solve()


K = int(input())
A = 7
count = 1
for i in range(K):
	if A % K == 0:
		print(count)
		break
	count += 1
	A = (10 * A + 7) % K
else:
	print('-1')


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


K = int(input())
num = 0
Num = 0
for i in range(K):
	num = Num * 10 + 7
	Num = num % K
	if Num == 0:
		print(i + 1)
		exit()
print(-1)


def main():
	k = int(input())
	li = 7
	if k % 2 == 0:
		print(-1)
		return
	for i in range(k):
		if li % k == 0:
			print(i + 1)
			break
		li = (li * 10 + 7) % k
	else:
		print(-1)

def __starting_point():
	main()
__starting_point()


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


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


K = int(input())
mod = 7
for i in range(K):
	mod = mod % K
	if mod == 0:
		print(i + 1)
		return
	else:
		mod *= 10
		mod += 7
print('-1')


N = int(input())
rm = 7 % N
ans = -1
for i in range(N):
	if rm == 0:
		ans = i + 1
		break
	rm = (rm * 10 + 7) % N
print(ans)


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


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


K = int(input())
if K % 2 == 0 or K % 5 == 0:
	print(-1)
else:
	n = 1
	Rem = 7 % K
	while Rem != 0:
		Rem = (Rem * 10 + 7) % K
		n += 1
	print(n)


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


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)


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


k = int(input())
if 7 % k == 0:
	print(1)
else:
	a = []
	a.append(7 % k)
	t = 0
	for i in range(2, k + 1):
		x = (10 * a[i - 2] + 7) % k
		if x == 0:
			print(i)
			break
		else:
			a.append(x)
			t += 1
	if t == k - 1:
		print(-1)


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


k = int(input())
if k % 2 == 0 or k % 5 == 0:
	print(-1)
	return
cnt = num = 0
while 1:
	num += 7 * pow(10, cnt, k)
	num %= k
	cnt += 1
	if num == 0:
		break
print(cnt)


K = int(input())
num = 7
for i in range(1000000):
	modnum = num % K
	if modnum == 0:
		print(i + 1)
		exit()
	num = modnum * 10 + 7
print(-1)


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


K = int(input())
seven = [0] * K
seven[0] = 7 % K
for i in range(1, K):
	seven[i] = (10 * seven[i - 1] + 7) % K
for i in range(K):
	if seven[i] == 0:
		print(i + 1)
		return
print(-1)


K = int(input())
if K % 2 == 0 or K % 5 == 0:
	print(-1)
	return
start = j = 7 % K
count = 1
while True:
	if j == 0:
		print(count)
		return
	j = 10 * j + 7
	j = j % K
	count += 1
	if j == start:
		print(-1)
		return


s = int(input())
r = 7
ret = -1
for a in range(1000000):
	if r % s == 0:
		ret = a + 1
		break
	else:
		r = (r * 10 + 7) % s
print(ret)


import sys
read = sys.stdin.read
from collections import defaultdict

def main():
	k = int(input())
	if k % 2 == 0:
		print(-1)
		return
	rems = defaultdict(int)
	n = 7 % k
	next_digit = 70 % k
	r = 1
	while True:
		if n == 0:
			print(r)
			return
		elif rems[n]:
			print(-1)
			return
		else:
			rems[n] = 1
			n += next_digit
			n = n % k
			next_digit = next_digit * 10 % k
			r += 1

def __starting_point():
	main()
__starting_point()


K = int(input())
x = 7 % K
ans = -1
for n in range(1, K + 10):
	if x == 0:
		ans = n
		break
	x = (x * 10 + 7) % K
print(ans)


k = int(input())
m = 0
for i in range(k):
	m = (m * 10 + 7) % k
	if m == 0:
		break
	elif i == k - 1:
		print(-1)
		exit()
print(i + 1)


k = int(input())
k9 = k * 9
l = 10
for n in range(1, k + 5):
	if l * 7 % k9 == 7 % k9:
		print(n)
		break
	l = l * 10 % k9
else:
	print(-1)


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


N = int(input())
D = 7 % N
for i in range(1, N + 1):
	if D == 0:
		print(i)
		exit()
	else:
		D = (10 * D + 7) % N
print(-1)


(s, k) = ('', int(input()))
for i in range(k):
	s += '7'
	s = str(int(s) % k)
	if not int(s):
		print(i + 1)
		break
else:
	print(-1)


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)


K = int(input())
(L, r) = (K * 9 if K % 7 else K * 9 // 7, 10)
for i in range(1, L + 1):
	r %= L
	if r == 1:
		print(i)
		exit()
	r *= 10
print(-1)


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


K = int(input())
mod = 7 % K
ans = -1
for k in range(K):
	if mod == 0:
		ans = k + 1
		break
	mod = (mod * 10 + 7) % K
print(ans)


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


import sys
k = int(input())
d = 0
for i in range(k + 1):
	d = 10 * d + 7
	d %= k
	if d == 0:
		print(i + 1)
		sys.exit()
print(-1)


K = int(input())
ans = 1
x = 7 % K
for i in range(K):
	if x != 0:
		ans += 1
		x = (x * 10 + 7) % K
if x == 0:
	print(ans)
else:
	print(-1)


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


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


K = int(input())
s = 0
for _ in range(K):
	s = (10 * s + 7) % K
	if s == 0:
		print(_ + 1)
		exit()
print(-1)


k = int(input())
rm = 7 % k
an = -1
for i in range(10 ** 6):
	if rm == 0:
		an = i + 1
		break
	rm = (rm * 10 + 7) % k
print(an)


k = int(input())
ans = -1
sm = 7
i = 1
if k % 2 == 0 or k % 5 == 0:
	ans = -1
elif sm % k == 0:
	ans = 1
else:
	while True:
		sm = (sm * 10 + 7) % k
		if sm == 0:
			ans = i + 1
			break
		i += 1
print(ans)


import sys
k = int(input())
r = 0
for i in range(1, k + 10):
	r *= 10
	r += 7
	r %= k
	if r == 0:
		print(i)
		return
print('-1')


a = int(input())
temp = 7
mod = temp % a
i = 1
if a % 2 == 0 or a % 5 == 0:
	print(-1)
	return
while mod != 0:
	mod = (mod * 10 + 7) % a
	i += 1
print(i)


K = int(input())
if K % 2 == 0 or K % 5 == 0:
	ans = -1
else:
	a = 1
	r = 7
	d = 70
	while True:
		if r % K == 0:
			ans = a
			break
		else:
			(r, d, a) = ((r + d) % K, d * 10 % K, a + 1)
print(ans)


import sys
k = int(input())
a = 7
a = a % k
for i in range(1000000):
	if a == 0:
		print(i + 1)
		return
	else:
		a = 10 * a + 7
		a = a % k
print('-1')


K = int(input())
n = 7
c = 0
while c <= K:
	n %= K
	c += 1
	if n == 0:
		print(c)
		exit()
	n = n * 10 + 7
print(-1)


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


k = int(input())
if k % 2 == 0 or k % 5 == 0:
	i = -1
else:
	l = 9 * k if k % 7 else 9 * k // 7
	(i, n) = (1, 10)
	while n % l != 1:
		n = n * 10 % l
		i += 1
print(i)


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


N = int(input())
ops = 0
if N % 2 == 0 or N % 5 == 0:
	ops = 1
else:
	if N % 7 == 0:
		L = 9 * N // 7
	else:
		L = 9 * N
	ch = 10 % L
	for i in range(1, N + 1):
		if ch == 1:
			ans = i
			break
		ch = 10 * ch % L
		if i == N + 1:
			ops = 1
if ops:
	print(-1)
else:
	print(ans)