object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a, b = sc.nextInt
  val (x, y) = if(a > b) (a ,b) else (b, a)
  println(resolve(x,y))


def mod(x:Int, y:Int) : Int = x % y

def resolve(x: Int , y:Int) : Int = {
  if(y == 0) x
  else resolve(y, mod(x, y))
}
}
