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

int main(){



  int i,n,p,max;
  int kouho[60];

  while(1){

    scanf("%d %d",&n,&p);
    if(n==0 && p==0)
      break;
    max = p;

    for(i=0;i<n;i++){
      kouho[i] = 0;
    }
    i=0;
    while(1){
      if(p>0){
	if(i<n){
	  kouho[i]++;
	  p--;
	}
	if(kouho[i] == max){
	  break;
	}
      }
      else if(p == 0){
	p = kouho[i];
	kouho[i]=0;
      }
      i++;
      if(i==n){
	i=0;
      }
    }
    printf("%d\n",i);
  

  }

}