import io.StdIn.readLong
import annotation.tailrec

object Main extends App {

  def isPrime(n: Long) = {
    val pfcsOf = (n: Long) => if (n < 4) Nil else 2L :: (3L to math.sqrt(n).toLong by 2).toList
    if (n < 2) false
    else pfcsOf(n).forall(n % _ != 0)
  }

  val primes = 2L #:: Stream.from(3, 2).map(_.toLong).filter(isPrime)

  @tailrec
  def primeFactorize(n: Long, pfs: List[Long]): List[Long] = {
    if (n == 1) pfs
    else {
      val Some(p) = primes.find(n % _ == 0)
      primeFactorize(n / p, p :: pfs)
    }
  }

  val n = readLong
  val pfs = primeFactorize(n, Nil).sorted

  def digitOf(n: Long) = math.log10(n).floor.toInt + 1

  val cands = n +: (for (i <- 1 to pfs.size) yield {
    n / pfs.take(i).product
  })

  println(cands.map(digitOf).filter(_ >= (digitOf(n) + 1) /2).min)
}
