require 'prime'
n = gets.to_i
primes = []
divisors = []

array = Prime.prime_division(n)
array.each do |a, b|
  b.times do
    primes.push(a)
  end
end

(1..primes.size).each do |i|
  primes.combination(i) do |prime|
    divisors << prime.inject{|a,b| a *= b}
  end
end

result = n
flag = true
divisors.each do |d|
  if result > n / d + d
    result = n / d + d

    if d == 1 || n / d == 1
      flag = true
    else
      flag = false
    end
  end
end

puts flag ? result - 1 : result - 2