import math

from functools import reduce

import collections



def prime_factorize(n):

    a = []

    while n % 2 == 0:

        a.append(2)

        n //= 2

    f = 3

    while f * f <= n:

        if n % f == 0:

            a.append(f)

            n //= f

        else:

            f += 2

    if n != 1:

        a.append(n)

    return a



def lcm_base(x, y):

    return (x * y) // math.gcd(x, y)



def lcm(*numbers):

    return reduce(lcm_base, numbers, 1)



def lcm_list(numbers):

    return reduce(lcm_base, numbers, 1)



def repfunc(x,y):

    a=x-1

    for i in range(1,x):

        if y%i==0 and (pow(10,i)-1)%x==0:

            a=i

            break

    return a





k=int(eval(input()))

res=1

ans1=0

ans2=0

if k%7==0:

    k//=7

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

    print((-1))

elif k ==1:

    print((1))

else:

    c=collections.Counter(prime_factorize(k))

    c2=list(c.keys())

    d=[0 for i in range(len(c2))]

    for i in range(len(c2)):

        if c2[i]==3:

            d[i]=pow(3,c[3])

        else:

            d[i]=repfunc(pow(c2[i],c[c2[i]]),pow(c2[i],c[c2[i]]-1)*(c2[i]-1))

    print((lcm_list(d)))

k=int(eval(input()))

if k%7==0:

    k//=7

res=1

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

    print((-1))

else:

    k*=9

    for i in range(k):

        res*=10

        if res%k==1:

            print((i+1))

            break

        else:

            res%=k

import math
from functools import reduce
import collections


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def repfunc(x, y):
    a = x - 1
    for i in range(1, x):
        if y % i == 0 and (pow(10, i) - 1) % x == 0:
            a = i
            break
    return a


k = int(eval(input()))
res = 1
ans1 = 0
ans2 = 0
if k % 7 == 0:
    k //= 7
if k % 2 == 0 or k % 5 == 0:
    print((-1))
elif k == 1:
    print((1))
else:
    c = collections.Counter(prime_factorize(k))
    c2 = list(c.keys())
    d = [0 for i in range(len(c2))]
    for i in range(len(c2)):
        if c2[i] == 3:
            d[i] = pow(3, c[3])
        else:
            d[i] = repfunc(pow(c2[i], c[c2[i]]), pow(c2[i], c[c2[i]] - 1) * (c2[i] - 1))
    print((lcm_list(d)))

k = int(eval(input()))
if k % 7 == 0:
    k //= 7
res = 1
if k % 2 == 0 or k % 5 == 0:
    print((-1))
else:
    k *= 9
    for i in range(k):
        res *= 10
        if res % k == 1:
            print((i + 1))
            break
        else:
            res %= k

-import math -from functools import reduce -import collections - - -def prime_factorize(n): -    a = [] -    while n % 2 == 0: -        a.append(2) -        n //= 2 -    f = 3 -    while f * f <= n: -        if n % f == 0: -            a.append(f) -            n //= f -        else: -            f += 2 -    if n != 1: -        a.append(n) -    return a - - -def lcm_base(x, y): -    return (x * y) // math.gcd(x, y) - - -def lcm(*numbers): -    return reduce(lcm_base, numbers, 1) - - -def lcm_list(numbers): -    return reduce(lcm_base, numbers, 1) - - -def repfunc(x, y): -    a = x - 1 -    for i in range(1, x): -        if y % i == 0 and (pow(10, i) - 1) % x == 0: -            a = i -            break -    return a - - -res = 1 -ans1 = 0 -ans2 = 0 +res = 1 -elif k == 1: -    print((1)) -    c = collections.Counter(prime_factorize(k)) -    c2 = list(c.keys()) -    d = [0 for i in range(len(c2))] -    for i in range(len(c2)): -        if c2[i] == 3: -            d[i] = pow(3, c[3]) +    k *= 9 +    for i in range(k): +        res *= 10 +        if res % k == 1: +            print((i + 1)) +            break -            d[i] = repfunc(pow(c2[i], c[c2[i]]), pow(c2[i], c[c2[i]] - 1) * (c2[i] - 1)) -    print((lcm_list(d))) +            res %= k