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

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

int x[53];

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

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