object Main extends App{
    // Your code here!
    def gcd(x:Int, y:Int): Int = {
        @scala.annotation.tailrec
        val t = (x,y)
        t match {
            case (0,_) => return y
            case (_,0) => return x
            case (_,_) => 0
        }
        (x >= y) match {
            case true => gcd(x%y, y)
            case false => gcd(x, y%x)
        }
    }
    val inputArray = io.StdIn.readLine().split(" ").map{_.toInt}
    println(gcd(inputArray(0), inputArray(1)))
}

