require 'prime'

a = gets.to_i

class Integer
  def my_divisor_list2
    return [1] if self == 1
    Prime.prime_division(self).map do |e|
      Array.new(e[1]+1).map.with_index do |element, i|
        e[0]**i
      end
    end.inject{|p,q| p.product(q)}.map do |a|
      [a].flatten.inject(&:*)
    end.sort
  end
end
b = a.my_divisor_list2
c = b.count / 2

x = b[c]
y =  b[c - 1]

if x == 1 && y == 1
  puts x + y - 1
  exit
end
puts x + y -2