open Printf
open Scanf

let solve n =
  let rec loop i mn =
    if i * i > n then mn
    else if n mod i = 0 then loop (i + 1) @@ min mn (i + n / i - 2)
    else loop (i + 1) mn in
  loop 1 n

let () =
  scanf "%d " solve |> printf "%d\n"
