while True:

    n,p = list(map(int,input().split()))

    if n==p==0: break

    s,c = [0]*n,p

    i = 0

    while True:

        if c:

            c-=1

            s[i%n]+=1

            if s[i%n]==p: break

        else:

            c+=s[i%n]

            s[i%n] = 0

        i+=1

    print((i%n))
while True:

    n,p = list(map(int,input().split()))

    if n==p==0: break

    l = [0]*n

    i,k = 0,p

    while True:

        i %= n

        if k==0: k,l[i] = l[i],0

        else:

            k-=1

            l[i]+=1

            if l[i]==p: break

        i+=1

    print(i)
while True:
    n, p = list(map(int, input().split()))
    if n == p == 0:
        break
    s, c = [0] * n, p
    i = 0
    while True:
        if c:
            c -= 1
            s[i % n] += 1
            if s[i % n] == p:
                break
        else:
            c += s[i % n]
            s[i % n] = 0
        i += 1
    print((i % n))

while True:
    n, p = list(map(int, input().split()))
    if n == p == 0:
        break
    l = [0] * n
    i, k = 0, p
    while True:
        i %= n
        if k == 0:
            k, l[i] = l[i], 0
        else:
            k -= 1
            l[i] += 1
            if l[i] == p:
                break
        i += 1
    print(i)

-    s, c = [0] * n, p -    i = 0 +    l = [0] * n +    i, k = 0, p -        if c: -            c -= 1 -            s[i % n] += 1 -            if s[i % n] == p: +        i %= n +        if k == 0: +            k, l[i] = l[i], 0 +        else: +            k -= 1 +            l[i] += 1 +            if l[i] == p: -        else: -            c += s[i % n] -            s[i % n] = 0 -    print((i % n)) +    print(i)