#include <stdio.h>

void init_can(int* can, int len) {
  int i;
  for(i=0;i<len;i++) can[i] = 0;
}

int main() {
  int n, p, candidate[50];

  while(1) {
    scanf("%d %d", &n, &p);
    if(n==0) break;

    init_can(candidate, n);

    int turn=0, bowl=p;
    while(!(bowl==0 && candidate[turn]==p)){
      if(bowl==0) {
	bowl = candidate[turn];
	candidate[turn] = 0;
      } else {
	candidate[turn]++;
	bowl--;
      }
      turn = (turn + 1) % n;
    }
    printf("%d\n", turn);
  }
  return 0;
}