distance' i j
	| i `mod` j == 0 = i `div` j + j - 2
	| otherwise      = distance' i (j - 1)

distance n = distance' n (isqrt n)
	where
		isqrt = floor . sqrt . fromIntegral

main :: IO ()
main = do
	n <- readLn
	print $ distance n
