numbers = []
input_num = gets.to_i

def prime?(n)
  return false if n < 2
  return true  if n == 2 or n == 3
  return false if (n % 2).zero?
  3.step(Math.sqrt(n).to_i, 2) {|i| return false if (n % i).zero?}
  true
end

if prime?(input_num)
  puts input_num - 1
else
  (2..input_num/2).each do |i|
    if input_num % i == 0
      numbers.push(i + input_num / i -2)
    end
  end
  puts numbers.sort![0]
end