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

divisors.uniq!

result = n
flag = true
(0..divisors.length).each do |i|
  if result > n / divisors[i] + divisors[i]
    result = n / divisors[i] + divisors[i]

    if divisors[i] == 1 || n / divisors[i] == 1
      flag = true
    else
      flag = false
    end
  end
end

puts flag ? result - 1 : result - 2
