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

dnums = nums.dup

until nums.length==2
  t = nums.shift*nums.shift
  nums.push(t)
  nums.sort!
end

until dnums.length==2
  t = dnums.shift*dnums.pop
  dnums.push(t)
  dnums.sort!
end



p [dnums.first+dnums.last-2, nums.first+nums.last-2].min


