while true
    n, p = gets.chomp.split.map(&:to_i)
    break if [n, p] == [0, 0]
    arr = Array.new(n, 0)
    player, cup = 0, p
    while true
        if cup != 0
            cup -= 1
            arr[player] += 1
            break if arr[player] == p
        else
            if arr[player] != 0
                cup += arr[player]
                arr[player] = 0
            end
        end
        player = (player + 1) % n
    end
    puts player
end

