input_data = gets.chomp.split(" ")
n = input_data[0].to_i
pStock = input_data[1].to_i

while n != 0 do 
    points = pStock
    
    nStones = []
    n.times do 
        nStones.push(0)
    end
    
    index = 0
    i = 0
    while true do
        if points > 0
            points -= 1
            nStones[i] += 1
        else
            flug = false
            n.times do |j|
                if nStones[j] == pStock
                    flug = true
                    index = j
                    break
                end
            end
            if flug == true
                break
            end
            points = nStones[i] 
            nStones[i] = 0
        end
        i += 1
        if i >= n 
            i = 0
        end
    end
    
    puts index

    input_data = gets.chomp.split(" ")
    n = input_data[0].to_i
    pStock = input_data[1].to_i
end
