#include<stdio.h>

int n, stone, player[50] = {0};

int game(){
  int i = 0, all_stones = stone;

  for(i = 0; i < 50; i++){
    player[i] = 0;
  }

  i = 0;

  while(1){
    if(stone == 0 ){
      if(player[i] == all_stones){
	return i;
      }
      stone = player[i];
      player[i] = 0;
      //      printf("player[%d] = %d\n-------stone = %d\n", i,  player[i], stone);
      i++;
      if(i >= n){
	i = 0;
      }

      continue;
    }
    stone--;
    player[i]++;
    //    printf("player[%d] = %d\n-------stone = %d\n", i,  player[i], stone);
    i++;
    if(i >= n){
      i = 0;
    }

  }
}

int main(void){
  int i;
  while(1){
    scanf("%d %d", &n, &stone);
    if(n == 0 && stone == 0){
      break;
    }

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

  }
  return 0;
}