#include <stdio.h>

typedef struct{
	int stone_num;	// number of stones in cup
	int turn;		// whose turn
}CUP;
CUP cup1;

int check(int n,int t,int *s){
	int i;
	for(i=0;i<n;i++){
		if((i != t) && (s[i] > 0)){
			return 1;	
		}
	}
	return 0;
}

void game(int n,int p){
	int i;
	int stone[50] = {0};		// number of stones players have
	cup1.stone_num = p;
	cup1.turn = 0;
	
	while(1){
		if(cup1.stone_num > 0){
			cup1.stone_num--;
			stone[cup1.turn]++;
			if(cup1.stone_num == 0){
				if(check(n,cup1.turn,stone) == 0){
					printf("%d\n",cup1.turn);
					break;
				}
			}
		}else{
			cup1.stone_num = stone[cup1.turn];
			stone[cup1.turn] = 0;
		}
		cup1.turn++;
		if(cup1.turn >= n) cup1.turn = 0;
	}
}

int main(void) {
	int n,p;
	scanf("%d %d",&n,&p);
	while(n != 0){
		game(n,p);
		scanf("%d %d",&n,&p);
	}
	return 0;
}