let calc n =
    let rec loop_i i acc =
        if i = 0 then acc else
            let acc = if n mod i = 0 then min acc (i + n / i - 2) else acc in
            loop_i (i - 1) acc
    in
    loop_i (int_of_float (sqrt (float n))) 9999999999999
;;
Scanf.sscanf (read_line ()) "%d" (fun n -> Printf.printf "%d\n" (calc n))