require 'prime'

n = gets.to_i
prime_div = n.prime_division
primes = []

prime_div.each do |i|
  i.last.times do
    primes << i.first
  end
end

while primes.size > 2
  m1 = primes.delete_at(primes.index(primes.min))
  m2 = primes.delete_at(primes.index(primes.min))
  primes.push m1*m2
end


p primes.size > 1 ? primes.first + primes.last - 2 : primes.first - 1