require 'prime'
n = gets.strip.to_i

ans = [1,1]
divs=Prime.prime_division(n)
nums = divs.map{|pr,c| [pr]*c } .flatten

if nums.length==1
  p n-1
  exit
end

result = n
Math.sqrt(n).to_i.times do |i|
  next unless (n%(i+2)).zero?
  tmp = (i+1 + n/(i+1))-2
  #p [n, n/(i+1)*n==n, tmp]
  result = [result, tmp].min
end


p result


