#include <stdio.h>

int main(void){
	int n, p, rikkouho[50], i, s;

	while (1){
		scanf("%d %d", &n, &p);
		if (n == 0 && p == 0) break;
		for (i = 0; i < n; i++){
			rikkouho[i] = 0;
		}

		i = 0; s = p;
		while (1){
			if (i == n) i = 0;
			if (s != 0){
				s--;
				rikkouho[i]++;
			}
			else{
				s = rikkouho[i];
				rikkouho[i] = 0;
			}
			if (rikkouho[i] == p) break;
			i++;
		}
		printf("%d\n", i);
	}
	return 0;
}