import scala.io.Source

object Main extends App {
  val Array(i, j) = Source.stdin.getLines.next.split(" ").map(_.toInt)

  def gcd(i: Int, j: Int): Int = {
    if (i % j == 0) j
    else gcd(j, i % j)
  }

  println(gcd(i, j))
}