factor :: Integer -> [Integer]
factor 1 = []
factor n = (prime:) . factor $ n `div` prime
  where divisors = dropWhile ((/=0) . mod n) [2..ceiling . sqrt $ fromIntegral n]
        prime = if null divisors
                then n
                else head divisors

solve :: Int -> [Integer] -> [Integer]
solve _ [a] = [a - 1]
solve 0 as = []
solve c as = x + y - 2 : solve (c - 1) as
  where x = product $ take c as
        y = product $ drop c as

main :: IO ()
main = do
  n <- readLn
  let res = factor n
  print . minimum $ solve (fromIntegral (length res - 1)) res
