object Main extends App {
  import scala.io.StdIn._


  val n = BigInt(readLine.trim)

  val half28 = (1 to 10).flatMap(digit ⇒ (0 until (1 << digit)).map(rank ⇒ make28(digit, rank))).filter(m ⇒ n % m == 0).toList

  println(solve(n, half28).let(i ⇒ if (i == 0) -1 else i))
  def solve(number: BigInt, factor: List[Long], count: Int = 0, max: Int = 0): Int = {
    if (number == 1) math.max(count, max)
    else {
      factor match {
        case Nil if number.is28 ⇒ math.max(count + 1, max)
        case Nil ⇒ max
        case h::t if number % h == 0 ⇒ solve(number, t, count, solve(number / h, factor, count + 1, max))
        case _::t ⇒ solve(number, t, count, max)
      }
    }
  }

  implicit class WrappedBigInt(val value: BigInt) extends AnyVal {
    def is28: Boolean = sub28(value)
    private[this] def sub28(value: BigInt): Boolean = {
      if (value == 0) true
      else (value % 10 == 8 || value % 10 == 2) && sub28(value / 10)
    }
  }

  def make28(digit: Int, rank: Int): Long = {
    (0 until digit).foldLeft(0){
      case (a, b) if ((1 << b) & rank) == 0 ⇒ a * 10 + 2
      case (a, _) ⇒ a * 10 + 8
    }
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
    @inline
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}
