#include<stdio.h>

int main()
{
  int bowl,stone;
  int mayor[50] ;
  int n,i;

  while(1){
    scanf("%d %d",&n,&stone);
    bowl = stone;

    if(n == 0 && stone == 0){
      break;
    }

    for(i = 0;i < n;i++){
        mayor[i] = 0;
    }

    i = 0;

    while(1){
      if(bowl != 0){
        mayor[i] = mayor[i] + 1;
        bowl = bowl - 1;
        if(mayor[i] == stone){
          break;
        }
      }
      else{
        bowl = mayor[i];
        mayor[i] = 0;
      }
      i++;

      if(i == n){
        i = 0;
      }
    }

    printf("%d\n",i);
  }

  return 0;
}