require 'prime'
a = gets.to_i

def divisors(n)
  n.prime_division.inject([1]) do |ary, (p, e)|
    (0..e).map{ |e1| p ** e1 }.product(ary).map{ |a, b| a * b }
  end.sort
end

nums = []
divisors(a).each do |i|
  nums << i + (a / i) - 2
end
puts nums.min
