# coding: utf-8
from math import sqrt


def solve(*args: str) -> str:
    k = int(args[0])

    l = 9*(k//7 if 0 == k % 7 else k)
    if 0 == l % 2 or 0 == l % 5:
        return '-1'

    r = phi = l
    for i in range(2, int(sqrt(l)+1)):
        if 0 == r % i:
            phi = phi*(i-1)//i
            while 0 == r % i:
                r //= i
    if 1 < r:
        phi = phi*(r-1)//r

    D = set()
    for d in range(1, int(sqrt(phi)+1)):
        if 0 == phi % d:
            D.add(d)
            D.add(phi//d)

    ret = -1
    for m in sorted(D):
        if 1 == pow(10, m, l):
            ret = m
            break

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines()))) from math import sqrt def solve(*args: str) -> str:
    k = int(args[0])

    l = 9*(k//7 if 0 == k % 7 else k)
    if 0 == l % 2 or 0 == l % 5:
        return '-1'

    r = phi = l
    for i in range(2, int(sqrt(l)+1)):
        if 0 == r % i:
            phi = phi*(i-1)//i
            while 0 == r % i:
                r //= i
    if 1 < r:
        phi = phi*(r-1)//r

    D = set()
    for d in range(1, int(sqrt(phi)+1)):
        if 0 == phi % d:
            D.add(d)
            D.add(phi//d)

    ret = -1
    for m in sorted(D):
        if 1 == pow(10, m, l):
            ret = m
            break

    return str(ret) solve k = int(args[0]) k int(args[0]) int args[0] args 0 l = 9*(k//7 if 0 == k % 7 else k) l 9*(k//7 if 0 == k % 7 else k) 9 k//7 if 0 == k % 7 else k 0 == k % 7 0 k % 7 k 7 k//7 k 7 k if 0 == l % 2 or 0 == l % 5:
        return '-1'

     0 == l % 2 or 0 == l % 5 0 == l % 2 0 l % 2 l 2 0 == l % 5 0 l % 5 l 5 return '-1' '-1' r = phi = l r l = phi = l phi l for i in range(2, int(sqrt(l)+1)):
        if 0 == r % i:
            phi = phi*(i-1)//i
            while 0 == r % i:
                r //= i
     i range(2, int(sqrt(l)+1)) range 2 int(sqrt(l)+1) int sqrt(l)+1 sqrt(l) sqrt l 1 if 0 == r % i:
            phi = phi*(i-1)//i
            while 0 == r % i:
                r //= i
     0 == r % i 0 r % i r i phi = phi*(i-1)//i phi phi*(i-1)//i phi*(i-1) phi i-1 i 1 i while 0 == r % i:
                r //= i
     0 == r % i 0 r % i r i r //= i r i if 1 < r:
        phi = phi*(r-1)//r

     1 < r 1 r phi = phi*(r-1)//r phi phi*(r-1)//r phi*(r-1) phi r-1 r 1 r D = set() D set() set for d in range(1, int(sqrt(phi)+1)):
        if 0 == phi % d:
            D.add(d)
            D.add(phi//d)

     d range(1, int(sqrt(phi)+1)) range 1 int(sqrt(phi)+1) int sqrt(phi)+1 sqrt(phi) sqrt phi 1 if 0 == phi % d:
            D.add(d)
            D.add(phi//d)

     0 == phi % d 0 phi % d phi d D.add(d) D.add D add d D.add(phi//d) D.add D add phi//d phi d ret = -1 ret -1 for m in sorted(D):
        if 1 == pow(10, m, l):
            ret = m
            break

     m sorted(D) sorted D if 1 == pow(10, m, l):
            ret = m
            break

     1 == pow(10, m, l) 1 pow(10, m, l) pow 10 m l ret = m ret m break return str(ret) str(ret) str ret *args: str if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines()))) __name__ == "__main__" __name__ "__main__" print(solve(*(open(0).read().splitlines()))) print solve(*(open(0).read().splitlines())) solve *(open(0).read().splitlines()) open(0).read().splitlines() (0).read().splitlines (0).read() (0).read (0) open 0 read splitlines def solve(*args: str) -> str:
    k = int(args[0])

    l = 9*(k//7 if 0 == k % 7 else k)
    if 0 == l % 2 or 0 == l % 5:
        return '-1'

    r = phi = l
    for i in range(2, int(sqrt(l)+1)):
        if 0 == r % i:
            phi = phi*(i-1)//i
            while 0 == r % i:
                r //= i
    if 1 < r:
        phi = phi*(r-1)//r

    D = set()
    for d in range(1, int(sqrt(phi)+1)):
        if 0 == phi % d:
            D.add(d)
            D.add(phi//d)

    ret = -1
    for m in sorted(D):
        if 1 == pow(10, m, l):
            ret = m
            break

    return str(ret) def solve(*args: str) -> str:
    k = int(args[0])

    l = 9*(k//7 if 0 == k % 7 else k)
    if 0 == l % 2 or 0 == l % 5:
        return '-1'

    r = phi = l
    for i in range(2, int(sqrt(l)+1)):
        if 0 == r % i:
            phi = phi*(i-1)//i
            while 0 == r % i:
                r //= i
    if 1 < r:
        phi = phi*(r-1)//r

    D = set()
    for d in range(1, int(sqrt(phi)+1)):
        if 0 == phi % d:
            D.add(d)
            D.add(phi//d)

    ret = -1
    for m in sorted(D):
        if 1 == pow(10, m, l):
            ret = m
            break

    return str(ret) solve
# coding: utf-8
from math import sqrt


def solve(*args: str) -> str:
    k = int(args[0])

    l = 9*(k//7 if 0 == k % 7 else k)
    if 0 == l % 2 or 0 == l % 5:
        return '-1'

    r = phi = l
    for i in range(2, int(sqrt(l)+1)):
        if 0 == r % i:
            phi = phi*(i-1)//i
            while 0 == r % i:
                r //= i
    if 1 < r:
        phi = phi*(r-1)//r

    D = set()
    for d in range(1, int(sqrt(phi)+1)):
        if 0 == phi % d:
            D.add(d)
            D.add(phi//d)

    ret = -1
    for m in sorted(D):
        if 1 == pow(10, m, l):
            ret = m
            break

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
