import scala.io.StdIn.readLine

object Main extends App {
  val Array(x, y) = readLine.split(" ").map(_.toInt)

  @scala.annotation.tailrec
  def gcd(x: Int, y: Int): Int = if (y == 0) x else gcd(y, x % y)

  println(gcd(x, y))
}
