loop do
class Integer
  def divide2
    ar = []
    1.upto(self ** 0.5) do |i|
      ar.push([i, self / i]) if (self % i).zero?
    end
    ar
  end
end
loc = Struct.new(:x,:y) do
  def dist(s,t)
    (s-x)+(t-y)
  end
end

n=gets.to_i
now=loc.new(1,1)
puts n.divide2.map{|loc| now.dist(loc[0],loc[1])}.min

end
