#include <stdio.h>

int is_winner(int turn, int *having_amount, int mayors) {
    int zero_condition = 1;
    int i;
    for (i = 0; i < mayors; i++) {
        if (i != turn) {
            zero_condition = zero_condition & (having_amount[i] == 0);
        }
    }
    return zero_condition;
}

int main(void) {
    int mayors;
    int pebbles_in_bowl;
    int i;

    while (1) {
        scanf("%d %d", &mayors, &pebbles_in_bowl);
        if (mayors == 0 && pebbles_in_bowl == 0)
            break;
        else {
            int turn = 0;
            int having_amount[mayors];

            // initialize
            for (i = 0; i < mayors; i++) {
                having_amount[i] = 0;
            }

            while (1) {
                if (pebbles_in_bowl == 0) {
                    pebbles_in_bowl += having_amount[turn];
                    having_amount[turn] = 0;
                }
                else if (pebbles_in_bowl == 1) {
                    if (is_winner(turn, having_amount, mayors)) {
                        printf("%d\n", turn);
                        break;
                    } else {
                        having_amount[turn]++;
                        pebbles_in_bowl--;
                    }
                } else {
                    having_amount[turn]++;
                    pebbles_in_bowl--;
                }

                // go to the next turn
                if (turn == mayors-1) {
                    turn = 0;
                } else {
                    turn++;
                }
            }
        }
    }

    return 0;
}