#include<stdio.h>

int main(void){
    int n=0,p=0;
    int box=0;
    // int hand[51]={0};
    int winner[10000]={-1};
    int count=0;
    while(1){
        int  hand[51]={0};
        winner[count]=-1;
        
        scanf("%d %d",&n,&p);
        if(n==0&&p==0){
            break;
        }
        box=p;
        while(1){
            for(int i=0;i<n;i++){
                if(box>0){
                    box-=1;
                    hand[i]+=1;
                    if(hand[i]==p){
                       
                        winner[count]=i;
                        break;
                    }
                }
                else if(box==0){
                    box=hand[i];
                    hand[i]=0;
                }
            }
            if(winner[count]!=-1){
               
                break;
            }
       
        }
        count++;
    }
    for(int i=0;i<count;i++){
        printf("%d\n",winner[i]);
    }
    return 0;
}
