#include <stdio.h>

int main() {
  int n, p, i, flag;
  int have[50];
  int turn;

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

    for(i = 0; i < n; i++) {
      have[i] = 0;
    }
    turn = 0;
    flag = 0;
    while(1) {
      if(p == 0) {
	p += have[turn];
	have[turn] = 0;
      } else {
	have[turn]++;
	p--;
	if(p == 0) {
	  flag = 1;
	  for(i = 0; i < n; i++) {
	    if(i == turn) continue;
	    if(have[i] >= 1) {
	      flag = 0;
	      break;
	    }
	  }
	  if(flag) {
	    printf("%d\n", turn);
	    break;
	  }
	}
      }
      turn++;
      if(!(turn < n)) turn = 0;
    }
  }
  return 0;
}