import Control.Applicative

main :: IO ()
main = do
  [a, b] <- map read . words <$> getLine
  print $ euclideanAlgorithm a b

euclideanAlgorithm :: Integral a => a -> a -> a
euclideanAlgorithm a 0 = abs a
euclideanAlgorithm a b = euclideanAlgorithm b (rem a b)

