import java.io.BufferedReader
import kotlin.system.exitProcess

fun main() {
    fun modPow(n: Long, k: Int, m: Long): Long {
        if (k == 0) {
            return 1L
        }
        var half = modPow(n, k shr 1, m)
        half *= half
        if (k and 1 == 1) {
            half %= m
            half *= n
        }
        return half % m
    }

    fun gcd(p: Int, q: Int): Int {
        return if (p == 0) q
        else if (q == 0) p
        else if (p and 1 == 0 && q and 1 == 0) gcd(p shr 1, q shr 1) shl 1
        else if (p and 1 == 0) gcd(p shr 1, q)
        else if (q and 1 == 0) gcd(p, q shr 1)
        else if (p > q) gcd((p - q) shr 1, q)
        else gcd(p, (q - p) shr 1)
    }

    val br = System.`in`.bufferedReader()
    var k = br.readInt()
    if (k % 7 == 0) {
        k /= 7
    }
    k *= 9

    if (k % 2 == 0 || k % 5 == 0) {
        print(-1)
        exitProcess(0)
    }

    var x = 1
    while (true) {
        if (modPow(10L, x, k.toLong()) == 1L) {
            print(x)
            exitProcess(0)
        }
        x++
    }
//    var lcm = 1
//    var i = 2
//    while (i * i <= k) {
//        var factor = 1
//        while (k % i == 0) {
//            factor *= i
//            k /= i
//        }
//        if (i == 3) {
//            factor /= 9
//            lcm = lcm * factor / gcd(lcm, factor)
//        } else if (factor != 1) {
//            var totient = (factor / i) * (i - 1)
//            while (totient and 1 == 0 && modPow(10L, totient shr 1, factor.toLong()) == 1L) {
//                totient /= 2
//            }
//
//            var temp = totient
//            while (temp and 1 == 0) {
//                temp /= 2
//            }
//            if (modPow(10L, totient / temp, factor.toLong()) == 1L) {
//                totient /= temp
//            }
//
//            lcm = lcm * totient / gcd(lcm, totient)
//        }
//        i++
//    }
//    if (k != 1) {
//        var totient = k - 1
//        while (totient and 1 == 0 && modPow(10L, totient shr 1, k.toLong()) == 1L) {
//            totient /= 2
//        }
//        var temp = totient
//        while (temp and 1 == 0) {
//            temp /= 2
//        }
//        if (modPow(10L, totient / temp, k.toLong()) == 1L) {
//            totient /= temp
//        }
//        lcm = lcm * totient / gcd(lcm, totient)
//    }
//    print(lcm)
}

private const val SPACE_INT = ' '.toInt()
private const val ZERO_INT = '0'.toInt()
private const val NL_INT = '\n'.toInt()

private fun BufferedReader.readInt(): Int {
    var ret = read()
    while (ret <= SPACE_INT) {
        ret = read()
    }
    val neg = ret == '-'.toInt()
    if (neg) {
        ret = read()
    }
    ret -= ZERO_INT
    var read = read()
    while (read >= ZERO_INT) {
        ret *= 10
        ret += read - ZERO_INT
        read = read()
    }

    while (read <= SPACE_INT && read != -1 && read != NL_INT) {
        mark(1)
        read = read()
    }
    if (read > SPACE_INT) {
        reset()
    }
    return if (neg) -ret else ret
}