import scala.io.StdIn._

object Main {
  def main(args: Array[String]) = {
    val a = readLine.split(' ').map(a => a.toInt)
    println(gcd(a(0), a(1)))
  }

  def gcd(x: Int, y: Int): Int = {
    if (x == y) x
    else if (x == 0) y
    else if (y == 0) x
    else if (x > y) gcd(y, x % y)
    else gcd(x, y % x)
  }
}