main = do w0 <- readLn d0 <- readLn let f w 1 = w f w d = f (w-w`div`(d*d)) (d-1) in print $ f w0 d0