#include <stdio.h>

int main(void){

int candid[50] = {0};
int n, p, i, mark;

while(1){
scanf("%d %d",&n,&p);
if(n == 0 && p == 0) break;

mark = p;

for(i =0;i <= 1000000;i++){
 if(p!=0){
  if(candid[i%n] == 0){
   candid[i%n] = p;
   p = 0;
}
else{
  candid[i%n]++;
  p--;
}
}

else{
 if(candid[i%n] != 0){
  p=candid[i%n];
candid[i%n] = 0;
}
}

if(candid[i%n] == mark) break;
}

printf("%d\n",i);
}
return 0;
}