require 'prime'
n = gets.to_i

factors = Prime.prime_division(n)

ary = []
factors.each {|p| p[1].times {|i| ary << p[0] } }

ary2 = [ary.pop]

while ary.size != 0 do
  aa = ary.shift(2).inject(:*)
  ary << aa
  ary.sort!
  ary2 << ary.pop
end

if ary2.size == 1
  puts ary2[0] - 1
else
  puts ary2.inject(:+) - 2
end