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 -> go 1 n $ [2..(sq n)] ++ [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

sq :: Int -> Int
sq n = sq' 0  (succ n)
  where
    sq' i j | succ i == j = i
            | m ^ 2 <= n = sq' m j
            | otherwise = sq' i m
      where
        m = (i + j) `div` 2

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