k = int(eval(input()))



# 解説AC

if k % 2 == 0 or k % 5 == 0:

    print((-1))

    exit()



num = 7

for i in range(k):

    if num % k == 0:

        print((i + 1))

        break

    num = (num % k) * 10 + 7

def makedivisor(N):  # 約数列挙

    p, upper, lower = 1, [], []

    while p * p <= N:

        if N % p == 0:

            lower.append(p)

            if p * p != N:

                upper.append(N // p)

        p += 1

    return lower + upper[::-1]





def totient(N):  # オイラーのトーシェント関数

    p, phi = 2, N

    while p * p <= N:

        if N % p == 0:

            phi = phi // p * (p - 1)

        while N % p == 0:

            N //= p

        p += 1

    if N > 1:

        phi = phi // N * (N - 1)

    return phi



k = int(eval(input())) * 9



# 解説AC オイラーの定理 O(n**0.5)

if k % 2 == 0 or k % 5 == 0:

    print((-1))

    exit()

if k % 7 == 0:

    k //= 7



cnt = totient(k)

num = makedivisor(cnt)

for i in num:

    if pow(10, i, k) == 1:

        print(i)

        break

k = int(eval(input()))
# 解説AC
if k % 2 == 0 or k % 5 == 0:
    print((-1))
    exit()
num = 7
for i in range(k):
    if num % k == 0:
        print((i + 1))
        break
    num = (num % k) * 10 + 7

def makedivisor(N):  # 約数列挙
    p, upper, lower = 1, [], []
    while p * p <= N:
        if N % p == 0:
            lower.append(p)
            if p * p != N:
                upper.append(N // p)
        p += 1
    return lower + upper[::-1]


def totient(N):  # オイラーのトーシェント関数
    p, phi = 2, N
    while p * p <= N:
        if N % p == 0:
            phi = phi // p * (p - 1)
        while N % p == 0:
            N //= p
        p += 1
    if N > 1:
        phi = phi // N * (N - 1)
    return phi


k = int(eval(input())) * 9
# 解説AC オイラーの定理 O(n**0.5)
if k % 2 == 0 or k % 5 == 0:
    print((-1))
    exit()
if k % 7 == 0:
    k //= 7
cnt = totient(k)
num = makedivisor(cnt)
for i in num:
    if pow(10, i, k) == 1:
        print(i)
        break

-k = int(eval(input())) -# 解説AC +def makedivisor(N):  # 約数列挙 +    p, upper, lower = 1, [], [] +    while p * p <= N: +        if N % p == 0: +            lower.append(p) +            if p * p != N: +                upper.append(N // p) +        p += 1 +    return lower + upper[::-1] + + +def totient(N):  # オイラーのトーシェント関数 +    p, phi = 2, N +    while p * p <= N: +        if N % p == 0: +            phi = phi // p * (p - 1) +        while N % p == 0: +            N //= p +        p += 1 +    if N > 1: +        phi = phi // N * (N - 1) +    return phi + + +k = int(eval(input())) * 9 +# 解説AC オイラーの定理 O(n**0.5) -num = 7 -for i in range(k): -    if num % k == 0: -        print((i + 1)) +if k % 7 == 0: +    k //= 7 +cnt = totient(k) +num = makedivisor(cnt) +for i in num: +    if pow(10, i, k) == 1: +        print(i) -    num = (num % k) * 10 + 7