(* O(√n log n) *)
let n = read_int () in
let f a b =
  let rec f acc n = if n = 0 then acc else f (acc + 1) @@ n / 10 in
  f 0 @@ max a b in
let rec loop acc i =
  if i * i > n then acc
  else if n mod i <> 0 then loop acc @@ i + 1
  else loop (min acc @@ f i @@ n / i) (i + 1) in
loop max_int 1 |> Printf.printf "%d\n"