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