from sys import stdin, stdout, stderr



while 1:

    n, p = list(map(int, stdin.readline().split()))



    if n + p == 0:

        break



    a = [0] * n

    wan = p



    for i in range(10**6):

        if wan > 0:

            a[i % n] += 1

            wan -= 1

        else:

            wan += a[i % n]

            a[i % n] = 0



        if a[i % n] == p:

            print((i % n))

            break
from sys import stdin, stdout, stderr



a = [0] * 50



while 1:

    n, p = list(map(int, stdin.readline().split()))



    if n + p == 0:

        break



    wan = p

    i = 0



    while a[i] < p:

        if wan > 0:

            a[i] += 1

            wan -= 1

        else:

            wan += a[i]

            a[i] = 0



        i = (i + 1) % n



    print(i)

    a[i] = 0
from sys import stdin, stdout, stderr

while 1:
    n, p = list(map(int, stdin.readline().split()))
    if n + p == 0:
        break
    a = [0] * n
    wan = p
    for i in range(10**6):
        if wan > 0:
            a[i % n] += 1
            wan -= 1
        else:
            wan += a[i % n]
            a[i % n] = 0
        if a[i % n] == p:
            print((i % n))
            break

from sys import stdin, stdout, stderr

a = [0] * 50
while 1:
    n, p = list(map(int, stdin.readline().split()))
    if n + p == 0:
        break
    wan = p
    i = 0
    while a[i] < p:
        if wan > 0:
            a[i] += 1
            wan -= 1
        else:
            wan += a[i]
            a[i] = 0
        i = (i + 1) % n
    print(i)
    a[i] = 0

+a = [0] * 50 -    a = [0] * n -    for i in range(10**6): +    i = 0 +    while a[i] < p: -            a[i % n] += 1 +            a[i] += 1 -            wan += a[i % n] -            a[i % n] = 0 -        if a[i % n] == p: -            print((i % n)) -            break +            wan += a[i] +            a[i] = 0 +        i = (i + 1) % n +    print(i) +    a[i] = 0