require 'prime'
n = gets.strip.to_i

ans = [1,1]
divs=Prime.prime_division(n)
nums = divs.map{|pr,c| [pr]*c } .flatten


if nums.length==1
  p n-1
  exit
end


#p nums

result = Float::INFINITY
(nums.length-1).times do|c|
#  p [nums[0..c], nums[c+1..-1]]
  temp = nums[0..c].inject(:*) + nums[c+1..-1].inject(:*)-2
  result = [temp, result].min
end

p result


