require 'prime'
def search factors
  if factors.length == 1
    puts factors[0] - 1
  elsif factors.length == 2
    puts factors[0]-1 + factors[1]-1
  else
    min_1 = factors.min
    factors.delete_at(factors.find_index(min_1))
    min_2 = factors.min
    factors.delete_at(factors.find_index(min_2))
    factors.push(min_1 * min_2)

    search(factors)
  end
end


n = gets.to_i
factors = n.prime_division.map {|p, e| [p] * e }.flatten
search(factors)