# frozen_string_literal: true

def factor(n)
  return [1] if n == 1

  `factor #{n}|sed -r 's/[0-9]+://g'|tr ' ' '\n'|sort -n`.split.map(&:to_i)
end

# Example: factors(100) => {2=>2, 5=>2}
def factors_and_num(n)
  factors = factor(n)
  ret = Hash.new(0)
  factors.each do |i|
    ret[i] += 1
  end
  ret
end

def uniq_factor(n)
  `factor #{n}|sed -r 's/[0-9]+://g'|tr ' ' '\n'|sort -n|uniq`.split.map(&:to_i)
end

n = gets.to_i

factors_hash = factors_and_num(n)

a = 1
b = 1
factors_hash.keys.each do |i|
  factors_hash[i].times do |_j|
    if a > b
      b *= i
    else
      a *= i
    end
  end
end

puts (a - 1) + (b - 1)
