main :: IO () main = do w <- readLn d <- readLn let ans = (w, d) : map (\(w1, d1) -> (w1-w1`div`d1^2, d1-1)) ans print $ fst $ ans !! (d-1)