#include <stdio.h>
#include <string.h>

int human_num;
int koisi_num[50];
int wan_num;
int wan_pos;

int main(void) {
	int start_wan_num;
	while(1) {
		scanf("%d%d",&human_num,&start_wan_num);
		if(human_num==0 && start_wan_num==0)break;
		memset(koisi_num,0,sizeof(koisi_num));
		wan_num=start_wan_num;
		wan_pos=0;
		while(1) {
			if(wan_num<=0) {
				wan_num=koisi_num[wan_pos];
				koisi_num[wan_pos]=0;
			} else {
				koisi_num[wan_pos]++;
				wan_num--;
				if(wan_num<=0 && koisi_num[wan_pos]==start_wan_num) {
					break;
				}
			}
			wan_pos++;
			if(wan_pos>=human_num)wan_pos=0;
		}
		printf("%d\n",wan_pos);
	}
	return 0;
}