import Control.Applicative

main :: IO ()
main = do
    [a, b] <- map read . words <$> getLine
    putStrLn $ show (solve a b)
    
solve :: Int -> Int -> Int 
solve a b = if b == 1 then a else if a >= b then mod a b else 1