#include<stdio.h>
int sum(int index,int n,int x[]){
    int sum=0;
    for(int i=0;i<n;i++){
        if(i==index) continue;
        sum+=x[i];
    }
    if(sum==0) return 1;
    else return 0;
}
int main(void){
    int i,n,p;
    while(1){
        scanf("%d%d",&n,&p);
        if(n+p==0) break;
        int cand[50]={0},box=p,ans=0;
        for(i=0;;i++){
            if(box==1&&sum(i%n,n,cand)){
                ans=i%n;
                break;
            }
            else if(box>0){
                box-=1;
                cand[i%n]+=1;
            }
            else{
                box+=cand[i%n];
                cand[i%n]=0;
            }
        }
        printf("%d\n",ans);
    }
}
