#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int max(int a,int b){if(a>b){return a;}return b;}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}

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

