object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new java.util.Scanner(System.in)
    var m, n = scanner.nextInt

    if(m < n) {
      val t = m
      m = n
      n = m
    }

    while(true) {
      if(n == 0) {
        println(m)
        System.exit(0)
      }
      val t = n
      n = m % n
      m = t
    }
  }
}

