require 'prime'
N = gets.to_i

primes = Prime.prime_division(N).map{|a,b|[a]*b}.flatten
result = N
1.upto(primes.size/2) do |i|
  primes.combination(i) do |arr|
    r = arr.inject(1){|sum,x| sum * x}
    r += N / r
    if r < result
      result = r
    end
  end
end
if result == N
  puts result - 1
else
  puts result - 2
end