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