#include<stdio.h>

int main(){
  int n, p, have[50], i, plate,winner;
  while(1){

    scanf("%d%d", &n, &p);

    if(n==0 && p==0) break;

    for(i=0; i<n; i++)have[i]=0;

    plate=p;

    i=0;

    while(1){
      
      if(plate!=0){
	have[i]++;
	plate--;
	if(have[i] == p && plate == 0){
	  winner=i;
	  break;
	}
	i++;
      }else{
	
	plate=have[i];
	have[i]=0;
	i++;

      }

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