#include<stdio.h>

int main(void){
  int i;
  int a[50];
  int n,p,c;

  while(1){
      scanf("%d %d",&n,&p);
      if(!n && !p){break;}
      c = p;
      for(i=0;i<n;i++)a[i] = 0; //óâªàÂ¬ÎÌðú»

      i = 0;
      do{
	if(c>0){
	  a[i]++;
	  c--;
	}else{
	  c = a[i];
	  a[i] = 0;
	}
	i++;
	if(i==n)i=0;
      }while(a[i]<p);
	
      printf("%d\n",i);
      
    }
  return 0;
}