#include <stdio.h>

int main() {

	int n, p, i = 0, j = 0,k,koisi;
	int N[50] = { 0 };
	int ans[10000] = {0};

	while (1) {
		scanf("%d %d", &n, &p);

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

		koisi = p;
		
		while (1) {
			if (p == 0) {
				p = N[i];
				N[i] = 0;
			}
			else {
				p--;
				N[i]++;
				if (N[i] == koisi) {
					ans[j] = i;
					break;
				}
			}
			i++;
			if (i == n)
				i = 0;
			
		}
		for (k = 0; k < n; k++)
			N[k] = 0;
		i = 0;
		j++;
	}
	
	for (i = 0; i < j; i++)
		printf("%d\n", ans[i]);

	return 0;
}