import qualified Data.ByteString.Char8 as BS
import qualified Data.Maybe as Maybe
import qualified Debug.Trace as Trace

solve :: Int -> Int
solve n = solveImpl (maxBound :: Int) 1 n

solveImpl :: Int -> Int -> Int -> Int
solveImpl tmpAns i n
    | i * i > n = tmpAns
    | otherwise =
        if (mod n i == 0)
            then if (tmp < tmpAns)
                then solveImpl tmp (i + 1) n
                else solveImpl tmpAns (i + 1) n
            else solveImpl tmpAns (i + 1) n
    where tmp = (i + (div n i)) - 2

main = do
    n <- (fst . Maybe.fromJust . BS.readInt) <$> BS.getLine
    let ans = solve n
    print ans