program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: k, n, ans
    logical,allocatable:: kishutu(:)

    read*, k
    allocate(kishutu(0:k), source = .false.)
    if (mod(k,7)==0) k=k/7
    n = mod(1,k)
    ans=1
    do while(n /= 0)
        if (kishutu(n)) then
            print'(i0)', -1
            stop
        end if
        kishutu(n) = .true.
        n = mod(n*10+1,k)
        ans=ans+1
    end do
    print'(i0)', ans
end program main