import scala.io.StdIn.readLine
import scala.annotation.tailrec
object Main {
    def main(args: String) {
        val input = readLine.split(" ").map(_.toInt).sorted
        println(gcd(input(0), input(1)))
    }
    @tailrec
    def gcd(a: Int, b: Int): Int = (a, b) match {
        case (x, y) if x % y == 0 => y
        case (x, y) => gcd(y, x % y)
    }
}
