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

int main(void){
	int ans,person[50],p,N,i,pp;
	while(1){
		scanf("%d %d",&N,&pp);
		if(N == 0 && pp == 0) break;
		p= pp;
		for(i = 0;i < N;i++){
			person[i] = 0;
		}
		ans = 0;
		while(1){
			if(p == 0){
				if(person[ans] == pp){
					break;
				}else{
					p = person[ans];
					person[ans] = 0;			
				}
			}else{
			//printf("%d  ",ans);
				person[ans]++;
				p--;			
			}
			ans = (ans + 1)%N;
		}

		printf("%d\n",ans);
	}
	
	return 0;
}