loop do
    n, p = gets.split.map(&:to_i)
    pp = p
    break if n == 0 && p == 0
    h = Array.new(n,0)
    i = 0
    loop do
        if p > 0
            h[i] += 1
            p -= 1
            break if h[i] == pp
        else
            p += h[i]
            h[i] = 0
        end
        i += 1
        i = 0 if i == n
    end
    puts i
end