require 'prime'
N = gets.chomp.to_i

factors = N.prime_division
factor = []
factors.each do |e|
  factor << e[0]
end
factor << 1
M = Math.sqrt(N).floor
while M >= 1 do
  if factor.include?(M)
    if N % M ==0
      break
    end
  end
  M -= 1
end

puts (M + N/M -  2)
