# frozen_string_literal: true

require 'prime'
n = gets.to_i

class Integer
  def divisors
    return [1] if self == 1

    Prime.prime_division(self).map do |e|
      Array.new(e[1] + 1).map.with_index do |_e, i|
        e[0]**i
      end
    end.reduce { |p, q| p.product(q) }.map do |a|
      [a].flatten.inject(&:*)
    end.sort
  end
end

mid = Math.sqrt(n)
ds = n.divisors.sort_by { |e| (e - mid).abs }

puts ds[0..1].map { |e| n / e + e - 2 }.min
