main::IO ()
main = do
    input <- getLine
    let s = truncate $ sqrt $ read input :: Int
    let t = read input :: Int
    let ans = filter (\x-> t `mod` x == 0) [1..s]
    print $ subtract 2 $ last ans + div t (last ans)