require 'prime'
N = gets.chomp.to_i
cnt = 0

if N.prime?
  puts N - 1
  exit
end

p = Prime.prime_division(N).map {|p, e| [p] * e }.flatten
sum = 1
(0..(p.length-2)).each do |i|
  sum *= p[i]
end
puts sum + p[p.length - 1] - 2