import java.util.*

fun main(args: Array<String>) {
    val array = readFromCli()
    greatestCommonFactor(array[0], array[1])
}

private fun readFromCli(): Array<Int> {
    val scanner = Scanner(System.`in`)
    val prog: MutableList<Int> = scanner
            .nextLine()
            .split(" ")
            .map{ it.toInt() }
            .toMutableList()
    scanner.close()

    return hint(prog[0], prog[1])
}

private fun greatestCommonFactor(x: Int, y: Int) {
    var a = x
    var b = y
    var r = a % b

    while (r != 0) {
        a = b
        b = r
        r = a % b
    }

    println(b.toString())
}

private fun hint(x: Int, y: Int): Array<Int> {
    return if (x > y) {
        arrayOf(y, x%y)
    } else {
        arrayOf(x, y)
    }
}
