import scala.io.StdIn.readLine;
object Main {
    def main(args: Array[String]): Unit = {
        val Array(x, y) = readLine.split(" ").map(_.toInt);
        println(gcd(x, y));
    }
    def gcd(x: Int, y: Int): Int = {
        if (x < y) {
            gcd(y, x);
        } else if (x % y == 0) {
            y;
        } else {
            gcd(y, x % y);
        }
    }
}
