let getQQList (n: int64) =
    let sqrtn = float n |> sqrt |> int64
    [| for a in 1L..sqrtn do
       if n % a = 0L then yield a + (n / a) - 2L |]

let n = stdin.ReadLine() |> int64
let ans = getQQList n |> Array.sort |> Array.head

printfn "%d" ans