#include<stdio.h>
#include<stdlib.h>

int main(void) {
    int n;
    int stone;
    int player[50];
    int i;
    int j;
    int sum;
    int have;

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

        have = 0;

        while(1) {
            sum=0;
            for(i=0; i<n; i++) {
                if(stone==0) {
                    stone = player[i];
                    player[i] = 0;
                }
                else {
                    stone--;
                    player[i]++;
                    if(stone==0) {
                        sum = 0;
                        for(j=0;j<n;j++) {
                            if(player[j] > 0) sum++;
                        }
                        if(sum==1) break;
                    }
                }
            }
            if(sum==1) {
                printf("%d\n", i);
                break;
            }
        }
        
    }
}