import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
    n <- getInt
    print $ solve n

solve :: Int -> Int
solve n = minimum [p + (n `div` p) - 2 | p <- [1..1000000], n `mod` p == 0]