fun main(args: Array<String>) {
    val array = readLine()!!.split(" ").map(String::toInt).toMutableList()
    var x = array[0]
    var y = array[1]
    val newArray = mutableListOf<Int>()

    var count = 1
    while (count != 0) {
        count = x % y
        if (count == 0) newArray.add(y) else newArray.add(count)
        x = y
        y = count
    }
    println(newArray.last())
}
