main = do
    n <- readLn :: IO Int
    let a = floor $ sqrt $ fromIntegral n
    let b = foldr (\a -> \b ->min a b) (n + 2) $ map (\x -> x + (n `div` x)) [x|x <- [1..a], n `mod` x == 0]
    putStrLn $ show (b - 2)