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