require 'prime'
n = gets.to_i

factors = Prime.prime_division(n)

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

(ary.size-2).times do
  aa = ary.shift(2).inject(:*)
  ary << aa
  ary.sort!
end

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