require 'prime'

n = gets.chomp.to_i

factors = n.prime_division
a = 1
b = 1
factors.reverse.each do |one|
  one[1].times do |i|
    if a > b
      b *= one[0]
    else
      a *= one[0]
    end
  end
end
result = a + b - 2
puts result
