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

int main()
{
	int candidateNum = 0, stoneNum = 0;
	while (scanf("%d %d", &candidateNum, &stoneNum) && candidateNum && stoneNum)
	{
		int *candidateArray = malloc(sizeof(int) * candidateNum);
		int stonePool = stoneNum;
		int counter = 0;
		while (1)
		{
			if (counter == candidateNum)
				counter = 0;
			if (*(candidateArray + counter) == stoneNum)
				break;
			if (stonePool > 0)
			{
				*(candidateArray + counter) += 1;
				stonePool--;
			}
			else
			{
				stonePool += *(candidateArray + counter);
				*(candidateArray + counter) = 0;
			}
			counter++;
		}
		printf("%d\n", counter);
	}
	return 0;
}
