factor :: Int -> [Int]
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

divide :: [Int] -> [([Int], [Int])]
divide [] = [([],[])]
divide (x:xs) = go ([x],[], xs, 1,length xs) []
  where
    go (a, b, [], i, j) zs = (a,b) : zs
    go (a, b, s@(x:xs), i, j) zs
       | i >= j = (a, b++s) : zs
       | (-i) >= j = (a++s, b) : zs
       | otherwise = go (x:a, b, xs, i+1, j-1) $ go (a, x:b, xs, i-1, j-1) zs

solve :: [Int] -> Integer
solve [] = 1
solve (a:as) = fromIntegral a * solve as

main :: IO ()
main = do
  n <- readLn
  let res = factor n
  print . minimum . map (\x -> solve (fst x) + solve (snd x) - 2) $ divide res
