#include<stdio.h>
#include<stdlib.h>

int main() {

	int n,p;
	int i;
	int cup,*member;
	int Answer[20],a=0;

	for(;;) {
		scanf("%d %d",&n,&p);
		if(n==0&&p==0) break;
		member=(int *)malloc(n * sizeof(int));
		for(i=0;i<n;i++)
			member[i]=0;

		i=0,cup=p;
		while(1) {
			if(cup>0) {
				cup--;
				member[i]++;
			}
			else if(cup==0&&member[i]>0){
				cup=member[i];
				member[i]=0;
			}
			if(member[i]==p) {
				Answer[a]=i;
				a++;
				break;
			}
			if(i==n-1) i=0;
			else i++;
		}

	}
	for(i=0;i<a;i++)
		printf("%d\n",Answer[i]);
	return 0;
}