let rec _solve n a b k =
  if n < k * k then
    if a < b then
      a * n + b - 2
    else
      a + b * n - 2
  else if n mod k == 0 then
    if a < b then
      _solve (n / k) (a * k) b k
    else
      _solve (n / k) a (b * k) k
  else _solve n a b (k + 1)

let solve n = print_int (_solve n 1 1 2)

let () = Scanf.scanf "%d" solve