// Aizu 1159: Next Mayor
// 2017.9.15 bal4u@uu

#include <stdio.h>
#include <string.h>

int x[53];

int main()
{
	int n, p, k, m, ans;

	while (scanf("%d%d", &n, &p) && n) {
		m = p, k = 0;
		memset(x, 0, sizeof(x));
		while(1) {
			if (m > 0) x[k]++, m--;
			else m += x[k], x[k] = 0;
			if (x[k] == p){ ans = k; break; }
			k++, k %= n;
		}
		printf("%d\n", ans);
	}
	return 0;
}