#include <stdio.h>

int main()
{
	int n, p, q, i, j, owan, buf[51];

	while (1) {
	// 人数読み込み
	scanf("%d %d", &n, &p);

	if (n == 0 && p == 0)
		break;

	// 初期化
	owan = p;
	for (i = 0; i < n; i++)
		buf[i] = 0;

	for (q = 0; !(owan == 0 && buf[q] == p); q = (q + 1) % n) {
		if (owan != 0) {
			buf[q]++;
			owan--;
		} else {
			owan = buf[q];
			buf[q] = 0;
		}
	}
	printf("%d\n", q);
	}
	return 0; 
}