#include <stdio.h>

int main(void){
	int i, j;
	int can[50];	//Candidate
	int n,p,c;
	while(1){
		scanf("%d%d",&n,&p);
		if(n==0&&p==0)	break;
		c = p;
		for(i=0;i<n;i++) can[i]=0;	//init Candidate
		i=0;
		do{
			if(c>0){
				can[i]++;
				c--;
			}else if(c==0){
				c=can[i];
				can[i]=0;
			}
			i++;
			if(i==n) i=0;
		}while(can[i]<p);
		printf("%d\n", i);
	}
	return 0;
}