n = gets.chomp.to_i

require 'prime'

def _divisors(primes, k)
  Enumerator.new do |y|
    if primes.size == k
      y << 1
    else
      p, e = primes[k]
      _divisors(primes, k + 1).each {|d|
        (e + 1).times {|e1|
          y << p ** e1 * d
        }
      }
    end
  end
end

def divisors(n)
  _divisors(Prime.prime_division(n), 0).to_a.sort
end

arr = divisors(n)
div = arr.size / 2

puts arr[div-1] + arr[div] -2


# if arr.size == 1
#   puts(n - 1)
# else
#   primes = []
#   arr.each do |v, i|
#     i.times do
#       primes.push v
#     end
#   end
#
#   if primes.size == 2
#     puts primes[0] + primes[1] - 2
#   else
#     ans = 0
#     primes.each.with_index do |p, j|
#     #   next if j == 0
#     #   if j == 1
#     #     ans += primes[0] + p - 2
#     #   else
#     #     ans = ans + p - 2 if ans < p
#     #     ans += primes[0] * p - primes[0] 
#     #   end
#     # end
#   end
#     puts ans
# end
