#include <stdio.h>

int main(){
    while (1) {
        int n,p,stone,i;
        scanf("%d %d",&n,&p);
        stone=p;
        if (n==0&&stone==0) return 0;
        int player[n];
        for (i=0; i<n; i++) {
            player[i]=0;
        }
        i=0;
        while (player[i%n]!=p) {
            if (stone==0) {
                stone=player[i%n];
                player[i%n]=0;
            }else{
                player[i%n]++;
                stone--;
            }
            i++;
        }
        printf("%d\n",i%n);
    }
}