object Main {
  def main(args: Array[String]): Unit = {
    val input = new java.util.Scanner(System.in)
    val a = input.nextInt
    val b = input.nextInt

    println(gcd(a, b))
  }

  def gcd(a: Int, b: Int): Int = if(b == 0){ a }else{gcd(b, a % b)}
}