#include <stdio.h>

int main(void){

  int n,p;
  int i,j;
  int bowl;

  for(;;){
    int mayor=51;
    scanf("%d %d",&n,&p);
    if(n==0&&p==0)break;
    bowl=p;

    int i=0;
    int cand[50]={0};

    for(;;){

      for(j=0;j<n;j++){
        if(cand[j]==p){
          mayor=j;
          break;
        }
      }

      if(mayor!=51)break;

      if(bowl!=0){
        cand[i%n]++;
        bowl--;
      }

      else if(bowl==0){
        bowl=cand[i%n];
        cand[i%n]=0;
      }

      i++;
    }

    printf("%d\n",mayor);

  }
  return 0;
}