#include<stdio.h>

int main(void) {
	int num_player;
	int player[50] = { 0 };
	int stone;
	int owner;
	int i=0;

	while(1) {
		player[i] = 0;
		i = -1;
		owner = 0;
		scanf("%d", &num_player);
		scanf("%d", &stone);
		if ((num_player == 0) && (stone == 0))
			break;
		while ((stone != 0) || (owner != 1)) {
			i++;
			if (i == num_player) {
				i = 0;
			}
			if (stone != 0) {
				player[i] += 1;
				stone -= 1;
				if (player[i] == 1) {
					owner += 1;
				}
			}
			else {
				if (player[i] != 0) {
					stone = player[i];
					player[i] = 0;
					owner -= 1;
				}
			}
		}
	printf("%d\n", i);
	}
	return 0;
}
