Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		n, _ := strconv.Atoi(chunks[0])
		p, _ := strconv.Atoi(chunks[1])
		cnts := make([]int, n, n)
		for i := 0; true; i++ {
			j := i % n
			if p == 0 {
				p, cnts[j] = cnts[j], 0
			} else {
				cnts[j]++
				p--
			}

			if p == 0 {
				noneCnt := 0
				winner := 0
				for j, c := range cnts {
					if c == 0 {
						noneCnt++
					} else {
						winner = j
					}
				}
				if noneCnt == n-1 {
					fmt.Println(winner)
					break
				}
			}
		}
	}
}

Python: while True:
    n, p = map(int, input().split())
    if n == 0 and p == 0:
        break

    own = [0 for i in range(n)]
    stone = p
    flag = True
    while flag:
        for i in range(n):
            if stone == 0:
                stone += own[i]
                own[i] = 0
            else:
                own[i] += 1
                stone -= 1
            if stone == 0 and own[i] == p:
                print(i)
                flag = False
                break

Python: while 1:
    n,p = map(int,input().split())
    if p+n<1:break
    man = [i for i in [0]*n]
    ball,a = p,0
    while p not in man:
        if ball >0:ball,man[a%n] =ball-1, man[a%n]+1
        elif ball == 0:ball,man[a%n] = man[a%n],ball
        a+=1
    print(man.index(max(man)))

Python: # -*- coding: utf-8 -*-

def main():
    while 1:
        n, p = list(map(int, input().split()))
        if n + p == 0:
            return 1
        s = [0] * n
        ans = -1
        while 1:
            if p > n:
                i = p // n
                p = p % n
                s = [s_ + i for s_ in s]
            else:
                for i in range(n):
                    if p > 0:
                        p -= 1
                        s[i] +=1
                        if p == 0 and sum(s)==s[i]:
                            ans = i
                            break
                    else:
                        p = s[i]
                        s[i] = 0
            if ans >-1:
                break
        print(ans)

if __name__ == "__main__":
    main()

Python: #!/usr/bin/python
# -*- coding: utf-8 -*-

def is_winner(having_amount):
    if having_amount.count(0) == len(having_amount) - 1:
        return True
    else:
        return False


def game(mayors, pebbles_in_bowl):
    turn = 0
    having_amount = [0 for i in range(mayors)]

    while True:
        if pebbles_in_bowl == 0:
            pebbles_in_bowl += having_amount[turn]
            having_amount[turn] = 0
        elif pebbles_in_bowl == 1:
            if is_winner(having_amount):
                print(turn)
                break
            else:
                having_amount[turn] += 1
                pebbles_in_bowl -= 1
        else:
            having_amount[turn] += 1
            pebbles_in_bowl -= 1

        # go to the next turn
        if turn == mayors - 1:
            turn = 0
        else:
            turn += 1

        print(*having_amount)

# having_amount[i] represents the amount of pebbles the
# candidate numbered i is having in the "turn"

winner_number = []

while True:
    mayors, pebbles_in_bowl = map(int, input().split())

    # action of a candidate
    if mayors == 0 and pebbles_in_bowl == 0:
        break

    else:
        game(mayors, pebbles_in_bowl)

Python: #!/usr/bin/python3

while True:
    n, p = list(map(int, input().split()))
    if n == 0 and p == 0: break

    candidates = [0] * n
    pebbles = p
    i = 0
    while True:
        #print(pebbles," ",candidates)

        if pebbles == 0:
            pebbles = candidates[i]
            candidates[i] = 0
        else:
            pebbles -= 1
            candidates[i] += 1
            if candidates[i] == p:
                break

        i += 1
        if i == n: 
            i = 0
    print(i)

Python: while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:
            ball-=1
            man[a]+=1
        elif ball == 0:ball,man[a] = man[a],ball
        if man[a]==p:break
        a+=1
    print(man.index(max(man)))

Python: while 1:
    n,p=map(int,input().split())
    if n==0:break
    a=[0]*n
    b,c=0,p
    while 1:
        b%=n
        if c==0:c,a[b]=a[b],0
        else:
            c-=1
            a[b]+=1
        if a[b]==p:break
        b+=1
    print(b)

Python: # n= 人数　p = 最初に入っている個数

def solve(n, p):
    tmp = p
    i = 0
    person = [0] * n
    while(1):
        if tmp != 0:
            person[i] += 1
            tmp -= 1
            if person[i] == p:
                return i
        else:
            tmp = person[i]
            person[i] = 0

        i += 1
        if i == n:
            i = 0

ans = []
while(1):
    n, p = map(int,input().split())
    if n == 0 and p == 0:
        for i in ans:
            print(i)

        break
    else:
        ans.append(solve(n, p))

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    n,p = map(int,input().split(" "))
    if n == 0 and p == 0:
        break
    P = [0 for i in range(n)]
    i = 0
    wan = p
    while P[i] != p:
        if wan == 0:
            wan = P[i]
            P[i] = 0
        else:
            P[i] += 1
            wan -= 1
        i = (i+1)%n
    print(i%n)

Python: while 1:
    n,p = map(int,input().split())
    if n==0: break
    a = [0 for _ in range(n)]
    while 1:
        for i in range(n):
            #print(i, a, p)
            if p != 0:
                a[i] += 1
                p -= 1
                if p == 0 and sum(a[:i])+sum(a[i+1:]) == 0:
                    print(i)
                    break
            else:
                p = a[i]
                a[i] = 0
        else:
            continue
        break

Python: while True:
    n,p = 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)

Python: # -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
#s = input()

while(True):
	n, p = map(int, input().split())
	if (n==0&p==0):break
	N = [0]*n
	owan = p
	turn = 0
	while(True):
		if turn == n:
			turn = 0
		
		if owan==0:
			owan = N[turn]
			N[turn] = 0
		else:
			owan -= 1
			N[turn] += 1

		if (N[turn] == p):
			break
		turn += 1
	print(turn)

Python: import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    while True:
        n,p = LI()
        mp = p
        if n == 0:
            break
        a = [0] * n
        i = 0
        while True:
            if p == 0:
                p = a[i]
                a[i] = 0
            else:
                a[i] += 1
                p -= 1
                if a[i] == mp:
                    break
            i = (i+1) % n
        rr.append(i)

    return '\n'.join(map(str, rr))


print(main())