require 'prime'
class Integer
  def divisor
    return [1] if self == 1
    pd=Prime.prime_division(self)
    first, *rest = pd.map do |p, k|
      (0..k).map{|i| p**i}
    end
    first.product(*rest).map do |a|
      a.inject(:*)
    end.sort
  end
end
io = STDIN
n=io.gets.to_i
div=n.divisor
size=div.size
if size.even?
  puts div[size/2-1]+div[size/2]-2
else
  puts div[size/2]*2-2
end
