K = int(eval(input()))

dic = {}

x = 0

count = 0

while 1:

    x = (x * 10 + 7) % K

    count += 1

    if x == 0:

        print(count)

        exit()

    if x in dic:

        print((-1))

        exit()

    dic[x] = 1

K = int(eval(input()))

x = 0

for i in range(K + 5):

    x = (x * 10 + 7) % K

    if x == 0:

        print((i + 1))

        exit()

print((-1))

K = int(eval(input()))
dic = {}
x = 0
count = 0
while 1:
    x = (x * 10 + 7) % K
    count += 1
    if x == 0:
        print(count)
        exit()
    if x in dic:
        print((-1))
        exit()
    dic[x] = 1

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

-dic = {} -count = 0 -while 1: +for i in range(K + 5): -    count += 1 -        print(count) +        print((i + 1)) -    if x in dic: -        print((-1)) -        exit() -    dic[x] = 1 +print((-1))