#include<stdio.h>

int game(int n, int p){
	int x[50]={0};    //n??????????£????
	int loop = 0;    //n??????????£?????????????????????????
	int stones = p;   //?????£?????????????????°
	while(1){
		if(loop == n)  //loop???n?????§?????£??????0?????????
			loop = 0;
		if(stones > 0){  //???????????£????????????
			x[loop]++;   //x[loop]???????????????????????¨???
			stones--;    //??????????????????
			if(x[loop] == p)   //x[loop]???????????????p???(??¨???)??????loop?????????
				return loop;
		}
		else if(x[loop] != 0){
				stones = x[loop];
				x[loop] = 0;
		}
		loop++;
	}
}

int main(){
	int n, p;
	scanf("%d %d",&n ,&p);
	while((n!=0)||(p!=0)){ //n=0??????p=0??¨???????????§??°?????????
		printf("%d\n", game(n, p));
		scanf("%d %d",&n ,&p);
	}
	return 0;