fun main(args:Array<String>):Unit {
    var (n, q) = readLine()!!.split(' ').map(String::toInt)
    while (n!=0 || q!=0){
    val list = Array(n) { 0 }
        val size = list.size
        var pos = 0
        var stock = q
        while (list.filter { it != 0 }.size != 1 || stock !=0) {
            if (stock > 0) {
                list[pos]++
                stock--
            } else {
                stock = list[pos]
                list[pos] = 0
            }
            pos = if (pos == size - 1) 0 else pos + 1
        }
        println(list.indexOfFirst { it != 0 })
        readLine()!!.split(' ').map(String::toInt).apply {
            n = first()
            q = last()
        }
    }
}
