#include <stdio.h>
int people[50];
int main(){
	int n,p;
	
	while (scanf("%d%d",&n,&p)!=EOF){
		if (n==0&&p==0) {
			break;
		}
		int flag=p;
		int output;
		int x;
		while (x<1000000) {
			for(int i=0;i<n;i++){
				if(p!=0){
					p=p-1;
					people[i]++;
					//printf("%d\n",p);
					//printf("%d\n",people[i]);


					if(people[i]==flag){
						output=i;
						goto print;
					}
				}
				
				//printf("%d\n",i);

				else if(p==0&&people[i]>0) {
					p=people[i];
					people[i]=0;					
				}
				else if (p==0&&people[i]==0) {
					goto out;
				}
				out:
					x++;
			}
		}
		print:
		printf("%d\n",output);

	}
}

