#include<stdio.h>


int main(){

  int n, p, cup, c[60];
  int i;

  while(scanf("%d %d", &n ,&p), n){
    cup=p;
    for(i=0;i<n;i++) c[i]=0;

    while(1){
      
      for(i=0;i<n;i++){
	if(cup!=0){
	  c[i]++;
	  cup--;
	  if(c[i]==p) break;
	}else if(c[i]!=0){
	  cup=c[i];
	  c[i]=0;
	}
      }
      if(i<n&&c[i]==p) break; 
    }
    printf("%d\n", i);
  }

  return 0;
}