foldlWithState :: (c -> a -> b -> (a, c)) -> c -> a -> [b] -> a
foldlWithState f s a l = fst $ foldl (\(a, s) -> f s a) (a, s) l

sqrtInt :: Integer -> Integer
sqrtInt x = floor (sqrt (fromIntegral x))

factors :: Integer -> [Integer]
factors n = foldlWithState step False [1, n] $ reverse [2..m]
    where m = sqrtInt n
          step s a x | s = (a, s)
                     | otherwise = if mod n x == 0 then ([x, div n x], True) else (a, s)

main = do
  n <- readLn :: IO Integer
  putStrLn $ show $ (\x -> (sum x) - 2) $ factors n
