require 'prime'

n = gets.chomp.to_i

def divisor_list(i)
  return [1] if i == 1
  i.prime_division.map do |e|
    Array.new(e[1]+1).map.with_index do |element, i|
      e[0]**i
    end
  end.inject{|p,q| p.product(q)}.map do |a|
    [a].flatten.inject(&:*)
  end.sort
end

min = Float::INFINITY
divisor_list(n).each do |d|
  a = n / d
  min = [min, a + d - 2].min
end

puts min
