import qualified Data.ByteString.Char8 as BS
import Data.Int (Int64)

main :: IO ()
main = do
  [x, y] <- map read . words <$> getLine :: IO [Int64]
  print $ solve x y


solve :: Int64 -> Int64 -> Int64
solve n k = 
   if k == 1 then
      0
   else
    gcd n k

test :: IO ()
test = do
  print $ solve 7 4
  print $ solve 2 6
  print $ solve 1000000000000000000 1
  putStrLn "test finished"