let rec sum10 n acc =
  let m = n / 10 in
  if m = 0 then n + acc
  else sum10 m (acc + (n mod 10))


let solve n =
  Array.init 10 (fun i -> sum10 (n * (i + 1)) 0)
  |> Array.fold_left min n

let () = Scanf.scanf "%d" solve |> Printf.printf "%d"