let scan_int () = Scanf.scanf " %d" (fun x -> x)
let print_int n = Printf.printf "%d\n" n

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

let init_val = int_of_float 1e12

let () =
  let n = scan_int() in
  print_int (solve 1 n init_val)