#include <stdio.h>

int candidate[50];
int n,p;

int isEnd(int i){
    int j;
    for(j=0;j<n;j++){
        if(candidate[j]&&j!=i) return 0;
    }
    printf("%d\n",i);
    return 1;
}

int main(void){
    int cup,i;
    while(scanf("%d %d",&n,&p),n||p){
        cup=p;
        for(i=0;i<n;i++){
            candidate[i]=0;
        }
        i=0;
        while(1){
            if(cup==0){
                cup=candidate[i];
                candidate[i]=0;
            }else{
                candidate[i]++;
                cup--;
                if(cup==0){
                    if(isEnd(i)) break;
                }
            }
            i=(i+1)%n;
        }
    }
    return 0;
}