#set
n = gets.chomp.to_i
pair_arr = Array.new
arr_count = 0
min_sum = n + 1
temp_sum = 0
arr_address = 0
answer = 0

#main
1.upto(n / 2) do |i|
  if n % i == 0 then
    j = n / i
    pair_arr[arr_count] = [i,j]
    arr_count += 1
  end
end

0.upto(arr_count - 1) do |x|
  temp_sum = pair_arr[x][0] + pair_arr[x][1]
  if temp_sum <= min_sum then
    min_sum = temp_sum
  end
end
answer = min_sum - 2
print ("#{answer}\n")