[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let inline gcd x y =
    let zero = LanguagePrimitives.GenericZero
    let rec loop x y = if y = zero then x else loop y (x % y)
    loop (abs x) (abs y)

[<EntryPoint>]
let main _ =
    let N = read int64
    let n = min N 1000000L
    let bs =
        [1L..n]
        |> List.map (fun x -> (x, N / x, N % x))
    let (c, d, _) =
        bs
        |> List.filter (fun (_, _, x) -> x = 0L)
        |> List.minBy (fun (x, y, _) -> abs (x - y))
    // eprintfn "*%A" (c, d)
    printfn "%i" (c - 1L + d - 1L)
    0