import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (a : b : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  print . f $ gcd a b

f :: Int -> Int
-- f = \n -> fst . foldl step (1, n) $ [2..(n `div` 2)]
f = \n -> go 1 n $ [2..n]
  where
    go k 1 _ = k
    go k _ [] = k
    go k m (i : is) | r /= 0 = go k m is
                    | otherwise = go (succ k) (g i q) is
      where
        (q, r) = m `divMod` i
    g i = h
      where
        h m | r /= 0 = m
            | otherwise = h q
          where
            (q, r) = m `divMod` i

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
