object GreatestCommonDivisor {
  def findGCD(x: Int, y: Int): Int = {
    val (small, large) = if (x < y) (x, y) else (y, x)
    if (small == 0) {
      large
    } else {
      findGCD(large % small, small)
    }
  }

  def main(args: Array[String]): Unit = {
    val xs = scala.io.StdIn.readLine().split(" ").toList.map(_.toInt)
    println(findGCD(xs(0), xs(1)))
  }
}